Casting Function Pointers

Theo Norvell norvell at csri.toronto.edu
Wed May 29 05:09:47 AEST 1991


In article <1991May28.124930.19893 at sco.COM> david at sco.COM (David Fiander) writes:
>>In article <16271 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>>>>I know of at least one -- it's no longer promised that casting a pointer to
>>>>integer and back preserves its value if the integer is big enough...
>>>
>on the Cybers, 
>
>	p == (char *)-1
>
>will have a different result from the test
>
>	(int)p == -1
>

It would be a bit much to expect there to be a bijection between 48 bit
pointers and 64 bit integers.  On recent 180 C compilers
	p == (char *)(int)p
which is what Doug was talking about.  The value is preserved, even if the
representation is not.  This is because pointer comparison ignores ring
numbers -- it has to or two pointers to the same object could
compare as different.



More information about the Comp.std.c mailing list