casting to a union

Bill Poser poser at csli.Stanford.EDU
Wed Dec 13 18:42:04 AEST 1989


Perhaps the simplest point to note about why  (union numstr) 7
is no good is to keep in mind that unions really are aggregates.
It is easy to fall into the trap of thinking of a union as a type
abstraction, so that a union that can hold either a character point
or an integer is a type that is one or the other, but that isn't
the case from C's point of view. Rather, a union is an aggregate
just like a struct except for the fact that the members share storage.
So the reason you can't cast 7 to (union numstr) is the same reason that
you can't cast it to a struct or an array.



More information about the Comp.lang.c mailing list