Skip to content

Instantly share code, notes, and snippets.

@matovitch
Created November 6, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matovitch/ff568c422ae165e56f761694e7f987f9 to your computer and use it in GitHub Desktop.
Save matovitch/ff568c422ae165e56f761694e7f987f9 to your computer and use it in GitHub Desktop.
#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