Submitter: Jens Gustedt
Reference Document: N/A
Subject: The order on
void pointers should be compatible.
If the type aliases
[u]intptr_t are present on a
platform, the address space that is used for
be linearized in such a way that a cast from such a pointer to
[u]intptr_t and back to
void* results in
the initial pointer value.
The standard is tacit on the underlying mapping between integer values and pointer values. But already the title of the corresponding section220.127.116.11 "Integer types capable of holding object pointers" suggest that this mapping would not be an arbitrary mapping (some kind of hash function), but that it should correspond to an interpretation of the bit representation of the pointer as an integer value.
Platforms for which the address space is not yet linear by itself
but segmented, can still easily map
void* to a larger
integer type, but the arithmetic for the integer interpretation and
pointer arithmetic (for the pointer seen as
must then not necessarily coincide.
The only advantage of representing a
void* in an
integer type are comparisons of values, even if the originating
pointer values potentially do not point into the same object (or one
element beyond). Unfortunately the current standard lacks to be
precise on how such comparisons can be performed.
Suggested Technical Corrigendum
Add 18.104.22.168 at the end:
It shall be implementation defined [variant: unspecified] whether
the mapping between the integer conversion and the pointer value is
order preserving or inverting. If
z are values of type
void* that point
to parts of the same object (or one element beyond) and that compare
ascending (ordered as
x ≤ y ≤ z), their
z' after conversion to
uintptr_t shall compare ascending (order preserving)
or descending (order inverting).
Previous Defect Report < - > Next Defect Report