Some people need a quote from the C ++ standard (I would put it in the comments to this answer if the format of the comments was not so limited), here are two of one from 1999:
5.2.10 / 3
The mapping done with reinterpret_cast is determined by the implementation.
5.2.10 / 5
An integral type or enumeration type value can be explicitly converted to a pointer. The pointer is converted to an integer of sufficient size (if ant exists in the implementation) and will have its original value back to the same type of pointer; mappings between pointers and integers are otherwise determined by the implementation.
And I do not see anything mandatory that such a mapping, defined by the implementation, should give a valid representation for all input data. Otherwise, an implementation in an architecture with address registers can be very well caught when executed.
p = (int*)10;
if the mapping does not give a view valid at that time (yes, what is a valid view for the pointer may be time dependent. For example, delete may invalidate the view of the remote pointer).
Aprogrammer
source share