On Tue, 02 Apr 2013 14:48:43 +0000, army1987 wrote:
> On Sat, 30 Mar 2013 11:13:50 -0700, Tim Rentsch wrote:
>> There is no guarantee that a pointer to any type other than void can be
>> converted to any integer type other than _Bool. A pointer to void can
>> be converted to the types [u]intptr_t, but only if the implementation
>> defines them, which the Standard does not require.
This is not quite correct. Any pointer type can be converted to any
integer type. In most cases, however, the result is implementation-
defined.
> Is there any good reason why (intptr_t)&i isn't required to be the same
> as (intptr_t)(void *)&i? (Crossposted to comp.std.c.)
The literal text of the standard only requires the conversion to
(u)intptr_t and back again to work for "any valid pointer to void".
As there is a similar requirement for conversions of other kinds of
object pointers to void * and back again, I can't think of a good
reason for why there is no requirement for conversion of other sorts of
object pointers to (u)intptr_t and back again to work.
If I encountered an implementation which provides (u)intptr_t but
conversions of non-void object pointers and back again did not work, I
would assume that this was either the result of malice on the part of the
implementators, or maybe they just ported some code from the DeathStation
9000.
Fortunately, in this situation the craziness would have to be documented
as the result is squarely in implementation-defined territory.