c/2820: unnamed union inside unnamed struct changes rest of the struct
redhog@mandrakesoft.com
redhog@mandrakesoft.com
Mon May 14 08:36:00 GMT 2001
>Number: 2820
>Category: c
>Synopsis: unnamed union inside unnamed struct changes rest of the struct
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon May 14 08:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: redhog@mandrakesoft.com
>Release: gcc version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)
>Organization:
>Environment:
>Description:
The existens of an unnamed union within an unnamed struct causes the locations of the _other_ elements of the struct to change.
In the example below, I supposed that the location of b would be the same in the two structs, but it is not.
>How-To-Repeat:
[redhog@lambda:~/Projects]$ cat test.c
#include <stdio.h>
struct
{
int x;
struct {
int a;
union {
int b;
int c;
};
};
} foo;
struct
{
int x;
struct {
int a;
int b;
int c;
};
} bar;
int main(int argc, char *argv[])
{
fprintf(stderr, "Foo: %i, %i, %i, %i\n", (int) &foo.x - (int) &foo, (int) &foo.a - (int) &foo, (int) &foo.b - (int) &foo, (int) &foo.c - (int) &foo);
fprintf(stderr, "Bar: %i, %i, %i, %i\n", (int) &bar.x - (int) &bar, (int) &bar.a - (int) &bar, (int) &bar.b - (int) &bar, (int) &bar.c - (int) &bar);
return 0;
}
[redhog@lambda:~/Projects]$ gcc -v test.c -o test -Wall
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.96/specs
gcc version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/cpp0 -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -Wall -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_pentium__ test.c /home/redhog/tmp/ccYmufW1.i
GNU CPP version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include
/usr/i586-mandrake-linux/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/cc1 /home/redhog/tmp/ccYmufW1.i -quiet -dumpbase test.c -Wall -version -o /home/redhog/tmp/ccmopfi4.s
GNU C version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk) (i586-mandrake-linux) compiled by GNU C version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk).
as -V -Qy -o /home/redhog/tmp/cccmRcqd.o /home/redhog/tmp/ccmopfi4.s
GNU assembler version 2.10.91 (i586-mandrake-linux) using BFD version 2.10.1.0.2
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o test /usr/lib/gcc-lib/i586-mandrake-linux/2.96/../../../crt1.o /usr/lib/gcc-lib/i586-mandrake-linux/2.96/../../../crti.o /usr/lib/gcc-lib/i586-mandrake-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i586-mandrake-linux/2.96 -L/usr/lib/gcc-lib/i586-mandrake-linux/2.96/../../../../i586-mandrake-linux/lib -L/usr/lib/gcc-lib/i586-mandrake-linux/2.96/../../.. /home/redhog/tmp/cccmRcqd.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i586-mandrake-linux/2.96/crtend.o /usr/lib/gcc-lib/i586-mandrake-linux/2.96/../../../crtn.o
[redhog@lambda:~/Projects]$ ./test
Foo: 0, 4, 4, 4
Bar: 0, 4, 8, 12
[redhog@lambda:~/Projects]$
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list