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

From: Kyle Moffett
Date: Sun Mar 26 2006 - 11:14:21 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/