Union type conversions
Joseph Nathan Hall
jnh at ece-csc.UUCP
Fri Jul 15 02:13:33 AEST 1988
In article <19845 at watmath.waterloo.edu> atbowler at watmath.waterloo.edu (Alan T. Bowler [SDG]) writes:
Actually I dn't think you are guaranteed anything more than
if you assign to a particular union member you can get back the
value you assigned by naming that member provided that you do
no assign to any other member. It is usual practice for a compiler
to put all members of a union at the same starting address
(i.e. equivalence them) however, there is no guarantee that
the compiler does not simply do the equivalent of
#define union struct
and proceed from there. Using union for a "pun" operation
...
Sorry, you're just plain wrong here. From page 140 of K&R, I quote:
"In effect, a union is a structure in which all members have
OFFSET ZERO [emphasis added], the structure is big enough to hold
the 'widest' member, and the alignment is appropriate for all
of the types in the union ..."
--
v v sssss|| joseph hall || 201-1D Hampton Lee Court
v v s s || jnh at ece-csc.ncsu.edu (Internet) || Cary, NC 27511
v sss || the opinions expressed herein are not necessarily those of my
-----------|| employer, north carolina state university . . . . . . . . . . .
More information about the Comp.lang.c
mailing list