I am wondering if you can use unions as arguments to a function:
Let's say I have two structures:
struct complex_attribute{
struct generic_attribute *sub_attributes[20];
};
struct generic_attribute{
int current_value;
};
And the combination of these two:
union union_attribute{
struct complex_attribute *complex;
struct generic_attribute *generic;
};
I want to create a function that accepts either complex_attribute or generic_attribute:
struct tagged_attribute* prepare_tagged_attribute(int code, union union_attribute *attribute)
However, when I call this function
prepare_tagged_attribute(2, pointer_to_complex_structure);
I get this error:
passing argument 2 of ‘prepare_tagged_attribute’ from incompatible pointer type
Therefore, I believe that a pointer to a complex structure is not necessarily a pointer to a type union (which makes sense) ... but then can unions be used this way?
source
share