Type punning in C
Lloyd Kremer
kremer at cs.odu.edu
Sat Oct 21 05:40:54 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.
Another way would be to back off one level of indirection, and transfer
the bit pattern by means of pointers to the respective objects.
Example:
float f;
int i;
/* assign f */
i = *(int *)&f; /* transfer bit pattern from f to i */
--
Lloyd Kremer
...!uunet!xanth!kremer
Have terminal...will hack!
More information about the Comp.lang.c
mailing list