Erroneous code using anonymous variables and constructors.
Ludovic WALLE
walle@inist.fr
Tue Oct 2 23:01:00 GMT 2001
The execution of the following code compiled with gcc:
struct x { int i; };
int main ()
{
struct { struct x *x; } a = { &((struct x) { 123456 } ) };
struct { struct x *x; } b = { &((struct x) { 123456 } ) };
struct { struct x *x; } c = { &((struct x) { 654321 } ) };
printf ("a.x: %p\n", a.x);
printf ("b.x: %p\n", b.x);
printf ("c.x: %p\n", c.x);
return (0);
}
generates the following output:
a.x: 400010e0
b.x: 400010e0
c.x: 400010e4
The struct x of variables a and b are the sames (same address) but they
shouldn't. They are different only if the initialisation value is
different (variable c).
Anonymous variables with the same initialisation seems to be abusively
merged .
I compiled the code with no options at all (gcc f.c).
gcc -v gives:
Reading specs from
/usr/local/gnu/gcc-2.95.2/lib/gcc-lib/hppa2.0w-hp-hpux11.00/2.95.2/specs
gcc version 2.95.2 19991024 (release)
More information about the Gcc-bugs
mailing list