Given an integer type IntT
such that sizeof(IntT) == sizeof(void*)
, and a variable of said type i
, is it guaranteed that reinterpret_cast<IntT>(reinterpret_cast<void*>(i)) == i
? This is similar to this question, but that question was looking at any arbitrary sized integer so the answer was a straight forward no. Limiting it to integers of exactly the same size as a pointer makes it more interesting.
It strikes me as though the answer would have to be "yes," because the specification states that there exists a mapping to any integer large enough to hold the pointer value. If the variables are the same size, then that mapping must be bijective. If it's bijective, then that also means the conversion from int
to void*
must also be bijective.
But is there a hole in that logic? Is there a wiggle word in the spec that I'm not accounting for?