José Bollo writes: > hi all, > > I repost here a problem that I met using GCC 3.4.4 and ABI for AMD64 > (-march=athlon64). > > the following C code > > typedef struct { > int32_t a; > void *b; > } S; > void fs() { > char t[255]; > int i; > for(i=0;i<255;i++) > t[i]=(char)(i+1); > } > int cmp1(S a1, S a2) { > return !memcmp(&a1,&a2,sizeof(S)); > } > int cmp2(S a1, S a2) { > return a1.a==a2.a && a1.b==a2.b; > } > void put(S y) { > int a,b; > S x; > x=y; > a=cmp1(x,y); > b=cmp2(x,y); > printf("a=%d b=%d\n",a,b); > } > int main() { > S a; > a.a=1; > a.b=&a; > fs(); > put(a); > return 0; > } > > compiled for my linux x86_64 using the amd64 ABI (-march=athlon64) with gcc > 3.4.4 prints "a=0 b=1"! > > i have seen why and it is clear to me how a such result is produced. > I add below a commented assembly listing of the incriminated part. > > i think that it is not a bug and that the structure can not be compared using > 'memcmp'. That's right. It's a consequence of 6.7.2.1 Para 13: "There may be unnamed padding within a structure object, but not at its beginning". Andrew.