Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement