initialize an array of union types
Hi,
I'm trying to the use the C99 designated initializer feature to initialize an array of union types, but I'm getting a compiler error as shown below. Am I using the correct syntax?
[code]#include <stdio.h>
union U
{
struct {int data;} a;
struct {int type; float data;} b;
};
int
main()
{
union U x = {.b.type = 2, .b.data = 1.0};
union U y[] = {{.b.type = 2, .b.data = 1.0}};
fprintf(stderr, "x b data: %f\n",x.b.data);
fprintf(stderr, "y b data: %f\n", y[0].b.data);
return 0;
}[/code]
% cc u.c
"u.c", line 13: structure/union designator used on non-struct/union type
"u.c", line 13: structure/union designator used on non-struct/union type
cc: acomp failed for u.c
% cc -Version
cc: Sun C 5.9 DEV 2006/06/08
%

