by sparkie · 1w ago · 0 comments
It's not the same argument because the type in this case is still a pointer (which is not strictly an integer).
The standard is quite clear about conversion between pointers and integers.
> An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, may not be correctly aligned, may not point to an entity of the referenced type, and can produce an indeterminate representation when stored into an object.
> Any pointer type may be converted to an integer type. Except as previously specified, the result is implementation-defined. If the result cannot be represented in the integer type, the behavior is undefined. The result is not required to be in the range of values of any integer type.
The purpose of `intptr_t` is to solve that last issue: it's an integer type sufficiently wide to hold a pointer, so that the result is in the range of values held by the intptr_t - and thus the round trip compares equal to the original pointer - but there's nothing else specified in the spec about intptr_t solving the other issues outlined in these clauses.
> 6.3.2.3 Pointers
> A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.
and
> 7.22.1.4 Integer types capable of holding object pointers
> The following type designates a signed integer type, other than a bit-precise integer type, with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:
> intptr_t
intptr_t is not like other integer types. It has special properties and guarantees that other integer types might not, even when they're the same width.
And I think your interpretation about dereferencing may be ruled out by 6.5.10p7:
> Two pointers compare equal if and only if both are null pointers, both are pointers to the same object....
That is, if they compare equal and one is a valid object pointer then the other is a valid object pointer, regardless of whether it was round-tripped through intptr_t/uintptr_t.