canonical values - an amenity

Joseph S. D. Yao jsdy at hadron.UUCP
Mon Dec 15 14:34:52 AEST 1986


In article <1542 at batcomputer.tn.cornell.edu> garry%cadif-oak at cu-arpa.cs.cornell.edu.arpa writes:
>the property that a pointer of any type cast to (void *) and back again
>is guaranteed to emerge unharmed.
>What I would like is to be able to do the same thing with *any* kind of
>(primitive) value, not merely pointer values!!! (Why do things half-way 
>in the language ??)
>	(unknown)pointer -> (double)(long)pointer
>	(unknown)long ->    (double)long

Unfortunately, there's no guarantee that a double will not lose
low-order bits in the mantissa when converting a long.  This is
especially a problem if the "long" happens to be a pointer.  E.g.,
32-bit long 0x7fffffff to 32-bit double with 8-bit exponent and
24-bit mantissa loses 8 bits of precision.  (Just f'r'instance.)
Unions are sometimes used for this purpose: they are guaranteed
to be as large as the largest object contained therein.
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
			jsdy at hadron.COM (not yet domainised)



More information about the Comp.lang.c mailing list