Section 7.18.1.4 of the C99 standard states:
The following type designates an unsigned integer type with the property that any valid pointer to
void
can be converted to this type, then converted back to pointer tovoid
, and the result will compare equal to the original pointer:
uintptr_t
Does this mean that only void *
types can be converted to uintptr_t
and back without changing the value of the original pointer?
In particular, I would like to know if the following code is required to use uintptr_t
:
int foo = 42;
void * bar = &foo;
uintptr_t baz = bar;
void * qux = baz;
int quux = *(int *)qux; /* quux == foo == 42 */
Or if this simpler version is guaranteed by the C99 standard to result in the same effect:
int foo = 42;
uintptr_t bar = &foo;
int baz = *(int *)bar; /* baz == foo == 42 */
Is a conversion to void *
required before converting a pointer to uintptr_t
and vice versa?