CKTIS / C++
std::uintptr_t — an integer type for holding a pointer value
std::uintptr_t from <cstdint> is an unsigned integer type that supports converting a valid void* to an integer and back without losing the pointer value. It is optional in C++23 and specifies neither a fixed width nor a portable address format.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <cstdint>
std::uintptr_t bits = reinterpret_cast<std::uintptr_t>(ptr);
void* restored = reinterpret_cast<void*>(bits);std::uintptr_t from <cstdint> is an alias for an unsigned integer type that allows a valid void* to be converted to an integer and then back to a void* that compares equal to the original pointer. In C++23 this type is optional; check availability with #if defined(UINTPTR_MAX) after including the header. The supplied reference points to the evolving working draft, which now requires this type — do not apply that requirement retroactively to C++23.
Perform the conversions explicitly with reinterpret_cast. The pointer-to-integer mapping is implementation-defined: the name promises neither exactly 32 or 64 bits nor the same size as void*. Do not extend the guarantee for void* to function pointers or pointers to members.
Keeping the integer unchanged and reconstructing the pointer does not extend the object's lifetime. Modifying the integer is not a portable substitute for pointer arithmetic and does not guarantee a pointer that can safely be used. Do not treat this integer as a persistent address to save across program runs.
The example converts from void* to std::uintptr_t and back while the local object still exists. It prints the comparison result instead of a run-dependent integer representing the address. The expected output when the type is available is true; otherwise the program prints std::uintptr_t unavailable.
Examples
#include <cstdint>
#include <iostream>
int main() {
#if defined(UINTPTR_MAX)
int value = 42;
void* original = &value;
std::uintptr_t bits = reinterpret_cast<std::uintptr_t>(original);
void* restored = reinterpret_cast<void*>(bits);
std::cout << std::boolalpha << (restored == original) << '\n';
#else
std::cout << "std::uintptr_t unavailable\n";
#endif
}
Result
true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.