6.29. Cast to a Union Type
6.29 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, not a cast, and hence does not yield an lvalue like normal casts. (See Compound Literals.)
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:
union foo { int i; double d; }; int x; double y;
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:
union foo u;
/* 登录查看完整内容