- Use
w->member->type
. - You need to allocate the
union
specifically.
One note that may be a point of misunderstanding is that the union
holds EITHER the int
, or TYPEA
, or TYPEB
, so in particular you cannot rely on your int type;
in the union to tell you which struct
the union holds.
Edit to respond to question in comments:
You probably want something like this:
struct TYPEA {
char data[30]; // or whatever
};
struct TYPEB {
double x, y; // or whatever
};
struct some_info {
int type; // set accordingly
union {
struct TYPEA a;
struct TYPEB b;
} data; // access with some_info_object.data.a or some_info_object.data.b
};