This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
comparison of structures
- From: José Bollo <jose dot bollo at tele2 dot fr>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 18 May 2006 16:14:02 +0200
- Subject: comparison of structures
hi,
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 think that it is not a bug and that the structure can not be compared using
'memcmp'.
do you agree or it a bug ?
regards
josé