Type punning in C

Luiz H de Figueiredo lhf at aries5.uucp
Wed Oct 11 01:06:14 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.

Provided both members have the same size!
Otherwise, try

union
{
 float f;
 unsigned char b[sizeof(float)];
};

-------------------------------------------------------------------------------
Luiz Henrique de Figueiredo		internet: lhf at aries5.uwaterloo.ca
Computer Systems Group			bitnet:   lhf at watcsg.bitnet
University of Waterloo
-------------------------------------------------------------------------------
eof



More information about the Comp.lang.c mailing list