// Illustration of reinterpret cast. #include #include #include // because of uintptr_t int main(){ using namespace std; // Casting between pointer and unsinged integers. int i; uintptr_t i_adr = reinterpret_cast(&i); // Casting the address of i to an an unsigned int cout << i_adr << endl << endl; int *j = reinterpret_cast(i_adr); // Casting the integer back to a pointer. assert(j == &i); // The roundtrip must succeed. // Attempting reinterpret cast from double to long long int: static_assert(sizeof(long long int) == sizeof(double), "unexpected sizes"); // Asserts statically that both types are of same byte length double e{124.567}; long long int m {reinterpret_cast(e)}; // Error: Attempting to reinterpret a double as a long long int // Doing the trick via pointers: double *pe{&e}; long long int *llip {reinterpret_cast(pe)}; // OK std::cout << *llip << std::endl; // 4638466040292848959 }