Re: Unnamed unions and C99 named initializers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jan Engelhardt <jengelh@xxxxxxxxxx> writes:

> 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.

This is a gcc extension.  It is not part of standard C.


> 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?

The gcc extension has apparently not been extended to support C99
designated initializers.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux