gcc: Cast to Union

1 
1 6.29 Cast to a Union Type
1 =========================
1 
1 A cast to union type looks similar to other casts, except that the type
1 specified is a union type.  You can specify the type either with the
1 'union' keyword or with a 'typedef' name that refers to a union.  A cast
1 to a union actually creates a compound literal and yields an lvalue, not
1 an rvalue like true casts do.  ⇒Compound Literals.
1 
1  The types that may be cast to the union type are those of the members
1 of the union.  Thus, given the following union and variables:
1 
1      union foo { int i; double d; };
1      int x;
1      double y;
1 
1 both 'x' and 'y' can be cast to type 'union foo'.
1 
1  Using the cast as the right-hand side of an assignment to a variable of
1 union type is equivalent to storing in a member of the union:
1 
1      union foo u;
1      /* ... */
1      u = (union foo) x  ==  u.i = x
1      u = (union foo) y  ==  u.d = y
1 
1  You can also use the union cast as a function argument:
1 
1      void hack (union foo);
1      /* ... */
1      hack ((union foo) x);
1