Unnamed unions and C99 named initializers

Jan Engelhardt jengelh@medozas.de
Tue Dec 16 02:46:00 GMT 2008


Hi,


let's begin with some code, point in case here, a struct with an unnamed 
union:

	struct foo {
		int a;
		union {
			int x;
		};
	};

Given this struct, it is possible to access the x by using ".x" on the 
struct:

	struct foo test;
	test.x = 7; /* works */

So essentially it behaves as if the union was not there. So far so good.
But if one can use .x on the struct in this way, why is not it possible 
to do the same in a C99 named initializer list?

	struct foo test = {.x = 7}; /* fails */

Seems kinda counter-intuitive. Did I spot a bug^W missing feature in the 
C99 standard?



More information about the Gcc-help mailing list