Type punning in C
Wade Guthrie
evil at arcturus.UUCP
Thu Oct 19 07:26:48 AEST 1989
>In article <11242 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
However, C does provide "union" types that can be used for such
purposes. Load the bit pattern into the integer union member
and extract it via the floating-point member.
lhf at aries5.uucp (Luiz H de Figueiredo) writes:
Provided both members have the same size! Otherwise, try
union
{
float f;
unsigned char b[sizeof(float)];
};
I thought that the standard said (as opposed to what I remember reading
in K&R I) that members of unions do NOT have to have zero offset? In
this case, none of the above work (and, BTW, breaks a lot of existing
code).
Do I completely misunderstand what the standard said, or is the stuff
above just not portable to ANSI conformant compilers (God, I didn't mean
for that to sound as snotty as it did -- please take that as a neophyte
asking an innocent question).
Wade Guthrie
evil at arcturus.UUCP
Rockwell International
Anaheim, CA
(Rockwell doesn't necessarily believe / stand by what I'm saying; how could
they when *I* don't even know what I'm talking about???)
More information about the Comp.lang.c
mailing list