If we use reinterpret_cast to bring a pointer to a pointer, an object to a pointer, or a pointer to an object, then the cast is correct.
int n = 0; char* c = reinterpret_cast<char*>(n); int another_value = reinterpret_cast<int>(c); Why doesn't reinterpret_cast allow casting on simple formats? This code is not going to:
int a = 0; char b = reinterpret_cast<char>(a); on Stroustrup:
reinterpret_castmanages conversions between unrelated types, such as integer to pointers or pointers to other (unrelated) pointers.
according to Myers:
reinterpret_castintended for low-level casts that generate implementation-dependent (i.e., unbearable) results, such as casting a pointer to anint.
So, both the pointer to the pointer, and the pointer to the int , and the int to the pointer are reinterpret_cast .
Alena L. writes in a blog :
reinterpret_cast- the most brash type conversion. Not portable, the result may be incorrect, no checks are done. It is believed that you know better than the compiler how things really are, and he quietly obeys. Cannot be cast one value to another value. Usually used to bring a pointer to a pointer, a pointer to a integer, an integer to a pointer. Can also work with links.
Well, one value to another cannot be cast. Why this opportunity is not filed?
reinterpret_cast? - AnT