You need to initialize the member of the union at compile time. Reading some articles, it seems that there is no other way than defining only the first entry in the union. If you are not using C99, you can define each member of the union specifically.
The thing is, I'm using Visual Studio 2010 Prof. it doesn't seem to support C99, or how can I enable ist? Or is there another way to initialize a member of a union?
thank
typedef union {
int a;
char *atxt;
} MY_UNION_t;
typedef struct {
int foo;
MY_UNION_t un;
}GEN_DATA_t;
GEN_DATA_t obj1 = {0,1};
GEN_DATA_t obj2 = {0,"bla"};
GEN_DATA_t obj3 = {0,.atext="bla"};
source
share