Created
April 9, 2019 12:55
-
-
Save a-square/d50086dff136e9c2a8c1fdaa68c05ce7 to your computer and use it in GitHub Desktop.
Binary value of (int TFoo::*)nullptr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <cstring> | |
#include <iostream> | |
struct TFoo { | |
int Bar; | |
int Baz; | |
}; | |
template <typename T, typename U> | |
inline T bit_cast(const U& value) { | |
static_assert(sizeof(T) == sizeof(U)); | |
T result; | |
memcpy(&result, &value, sizeof(value)); | |
return result; | |
} | |
int main() { | |
std::cout | |
<< "Equality: " | |
<< (&TFoo::Bar == nullptr) << ' ' | |
<< (&TFoo::Baz == nullptr) << std::endl; | |
std::cout | |
<< "Representation: " | |
<< "ULONG_MAX = " << ULONG_MAX << ", " | |
<< "(int TFoo::*)nullptr = " << bit_cast<size_t>((int TFoo::*)nullptr) << ", " | |
<< "&TFoo::Bar = " << bit_cast<size_t>(&TFoo::Bar) << ", " | |
<< "&TFoo::Baz = " << bit_cast<size_t>(&TFoo::Baz) << std::endl; | |
std::cout | |
<< "Sizes: " | |
<< sizeof(&TFoo::Bar) << ' ' | |
<< sizeof(&TFoo::Baz) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment