lkml.org 
[lkml]   [2006]   [Mar]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC][PATCH 1/2] Create initial kernel ABI header infrastructure
Date
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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-03-26 18:19    [W:0.115 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site