[RFC][PATCH 1/2] Create initial kernel ABI header infrastructure

Kyle Moffett mrmacman_g4 at mac.com
Sun Mar 26 18:16:48 CEST 2006


On Mar 26, 2006, at 10:38:59, Martin Mares wrote:
>> It _is_ fragile, but for a number of POSIX-defined structs that's  
>> actually the only way to do it without duplicating the data  
>> structure in entirety, unless the GCC people can implement a  
>> "typedef struct foo struct bar;"
>
> Actually, something like that can be achieved using anonymous  
> structure members:
>
> struct xxx {
> 	struct yyy;
> };

Oh, if only that worked.  Actually, what happens is the "struct yyy;"  
declaration inside of struct xxx looks just like "struct yyy;" out in  
the middle of some random header file.  It predeclares the existence  
of a struct yyy and does nothing else.

For instance, the following sample program:
   struct foo {
   	int a;
   	int b;
   };

   struct bar {
   	struct foo;
   };

   int main()
   {
   	struct foo myfoo = { .a = 1, .b = 2 };
   	struct bar mybar = { .a = 1, .b = 2 };
   	return 0;
   }

Compiled like this:
   gcc mytest.c -o mytest

Generates these errors:
   mytest.c:7: warning: declaration does not declare anything
   mytest.c: In function `main':
   mytest.c:12: error: unknown field `a' specified in initializer
   mytest.c:12: warning: excess elements in struct initializer
   mytest.c:12: warning: (near initialization for `mybar')
   mytest.c:12: error: unknown field `b' specified in initializer
   mytest.c:12: warning: excess elements in struct initializer
   mytest.c:12: warning: (near initialization for `mybar')

Cheers,
Kyle Moffett



More information about the llh-discuss mailing list