This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi Folks, I'm a newbie here, so I hope this is the right ML to send this query to. I have a problem when compiling the test.c program below using gcc 3.3 (C compiler) under Linux (RH 7.2) on my i686 architecture. The compiler doesn't allow an unnamed struct inside a named struct even though the unnamed struct ("wibble") is declared before it. I have used "gcc -Wall -save-temps test.c -o test" to generate the preprocessed "test.i" file attached. Here is the original source of only a few lines to give you a quick understanding of the problem. #include <stdio.h> struct wibble { int a; }; struct wabble { struct wibble; /**** Compiler throws a wobbly here! ****/ int b; }; struct wabble wabble_init = { {.a = 1,}, .b = 4, }; int main(void) { struct wabble *ptr = &wabble_init; ptr->a=10; ptr->b=12; printf("Sizeof struct wibble = %d bytes\n", sizeof(struct wibble)); printf("Sizeof struct wabble = %d bytes\n", sizeof(struct wabble)); return 0; } The compiler produces the following error message: test.c:8: warning: declaration does not declare anything test.c:13: warning: braces around scalar initializer test.c:13: warning: (near initialization for `wabble_init.b') test.c:13: error: field name not in record or union initializer test.c:13: error: (near initialization for `wabble_init.b') test.c: In function `main': test.c:21: error: structure has no member named `a' Now under earlier versions of gcc (3.2 and 2.96) no errors or warnings are produced. I have also compiled this code under MS VC++ Version 6.0 with success (not that I program under Windozzz). Surely, the elements/fields of this unnamed structure wibble should be accessible as though they were part of the main structure "wabble" (e.g. ptr->a). This is how earlier versions of gcc handled this and is a feature that I definitely use/need for my code. Can someone let me know if this bug has been fixed in later releases of gcc and why does gcc 3.3 generate this error? Many TIA, Rob : ) (See attached file: test.i)
Attachment:
test.i
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |