Type punning in C

Henry Spencer henry at utzoo.uucp
Sun Oct 8 10:58:08 AEST 1989


In article <475 at idacrd.UUCP> desj at idacrd.UUCP (David desJardins) writes:
>   Does anyone have any ideas on how one should go about converting an
>integer to the floating-point number with the same bit pattern?  ...
>   It doesn't seem that there is any equally straightforward way to
>accomplish this in C.  I don't want to involve pointers ...

You might try unions.  This is one of the things they're good for,
albeit in a very implementation-specific way.  (Not a problem here,
since the operation is inherently implementation-specific.)

If your compiler won't put unions into registers, complain to your supplier.  
-- 
A bit of tolerance is worth a  |     Henry Spencer at U of Toronto Zoology
megabyte of flaming.           | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list