Dereferencing Typecast Integer Literals

Doug Gwyn gwyn at smoke.brl.mil
Wed Feb 6 06:35:10 AEST 1991


In article <1991Feb4.234142.26867 at watmath.waterloo.edu> datangua at watmath.waterloo.edu (David Tanguay) writes:
>In article <15067 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>>Also, each implementation is required to
>>provide SOME integral type to which any data pointer can be cast such
>>that upon subsequent cast back to the same type of pointer, the new
>>pointer value will compare equal to the old value.
>Where does the standard say this?  3.3.4 says a pointer may be converted
>to some integral type, and that an integer may be converted to a pointer,
>but the result is implementation defined.

Oops, you're right.  The base document made the guarantee, but somewhere
along the way X3J11 decided that it was impractical to guarantee that
the same representation would be obtained upon reconversion to a pointer,
and that they did not want to require implementation of the "equivalence
class" notion for pointer equality that I mentioned previously.  There is
an even more insidious problem lurking in the way the standard ended up,
which is that an ARBITRARY integral value must be convertible to any
pointer type, whether or not alignment and address bound requirements are
met.  This could cause implementations to have to perform some extra work
when an integer is converted to some pointer types.

Sorry for relying on my fuzzy memory instead of on the standard..



More information about the Comp.std.c mailing list