Contents|Index|Previous|Next
 Cast to a union type  

A cast to union type is similar to other casts, except that the type specified is a union type. You can specify the type either with union tag or with a typedef name. A cast to union is actually a constructor though, not a cast, and hence does not yield an lvalue like normal casts. (See Constructor Expressions.)

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.

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. You can also use the union cast as a function argument: