Union type conversions
Karl Heuer
karl at haddock.ISC.COM
Sat Jul 16 02:24:44 AEST 1988
In article <12490 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <3714 at ece-csc.UUCP> jnh at ece-csc.UUCP (Joseph Nathan Hall) writes:
>[quoting from the *de*scriptive part of the text [K&R], which says only that]
>> "In effect, a union is a structure in which all members have
>> OFFSET ZERO [emphasis added] ..."
>
>The point of this quote is to warn users that writing on any one
>element of a union *may* stomp any other element, not that it *must*
>stomp other elements. Alan Bowler is right; unions make few
>guarantees. On the other hand, a compiler that does not conserve
>storage with union definitions is probably not worth using.
Except possibly as a debugging tool to catch accidental punning.
Anyway, the dpANS does guarantee that "a pointer to a union object, suitably
cast, points to each of its members ... and vice versa" (3.5.2.1). So an
implementation that tries to make structs out of unions would have to do some
gymnastics if it's to remain ANSI-conformant.
Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
More information about the Comp.lang.c
mailing list