Created
November 6, 2018 19:38
-
-
Save matovitch/ff568c422ae165e56f761694e7f987f9 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
enum class Endianness | |
{ | |
LITTLE, | |
BIG | |
}; | |
Endianness makeEndianness() | |
{ | |
union U | |
{ | |
uint8_t u8; | |
uint16_t u16 = 1; | |
}; | |
return U{}.u8 ? Endianness::LITTLE | |
: Endianness::BIG; | |
} | |
static const auto ENDIANNESS = makeEndianness(); | |
int main() | |
{ | |
if (ENDIANNESS == Endianness::LITTLE ) { std::cout << "LITTLE" << std::endl; } | |
if (ENDIANNESS == Endianness::BIG ) { std::cout << "BIG" << std::endl; } | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment