Defect report #4nn

Previous Defect Report < - > Next Defect Report

Submitter: Jens Gustedt
Submission Date:
2012-10-08 Source:
Reference Document: N/A
Version: 1.0
Date: 2012-10-08
Subject: The order on uintptr_t and void pointers should be compatible.


If the type aliases [u]intptr_t are present on a platform, the address space that is used for void* can be linearized in such a way that a cast from such a pointer to an [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 section7.20.1.4 "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 char*, e.g) 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 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 x, y and 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 corresponding values x', y' and z' after conversion to intptr_t or uintptr_t shall compare ascending (order preserving) or descending (order inverting).

Previous Defect Report < - > Next Defect Report