The types that may be cast to the union type are those of the members of the union. Thus, given the following union and variables, both ‘x’ and ‘y’ can be cast to type union foo.
union foo { int i; double d; };
int x;
double y;Using the cast as the right-hand side of an assignment to a variable of union type is equivalent to storing in a member of the union, like the following.
union foo u; ... u = (union foo) x _ u.i = x u = (union foo) y _ u.d = yYou can also use the union cast as a function argument:
void hack (union foo); ... hack ((union foo) x);