I have the following struct:
struct type1 {
struct type2 *node;
union element {
struct type3 *e;
int val;
};
};
When initialising a pointer *f that points to an instance of type1 and doing something like:
f.element->e or even just f.element, I get:
error: request for member ‘element’ in something not a structure or union
What am I overseeing here?
f? Maybe you meanf->element.e?elementis the union tag, not a member name. Try withstruct { ... union element { ... } elem; };andf.elem.structmember needs a name to access it. The name is given after the type.struct type1 { ... ; union { ... } element; };would create a memberelementwith type (untagged)union {...}.