Edit #2
So after looking into how the bits might be stored on different systems, I finally realized that I might be able to just use a single bit to test for endianness. It looks to be much less error-prone than using an array and I still get the correct answer on my Windows box.
enum hl_endianness : uint32_t {
HL_LITTLE_ENDIAN = 0x00000001,
HL_BIG_ENDIAN = 0x01000000,
HL_PDP_ENDIAN = 0x00010000,
HL_UNKNOWN_ENDIAN = 0xFFFFFFFF
};
/**
* A simple function that can be used to help determine a program's endianness
* at compile-time.
*/
constexpr hl_endianness getEndianOrder() {
return
((1 & 0xFFFFFFFF) == HL_LITTLE_ENDIAN)
? HL_LITTLE_ENDIAN
: ((1 & 0xFFFFFFFF) == HL_BIG_ENDIAN)
? HL_BIG_ENDIAN
: ((1 & 0xFFFFFFFF) == HL_PDP_ENDIAN)
? HL_PDP_ENDIAN
: HL_UNKNOWN_ENDIAN;
}
#define HL_ENDIANNESS getEndianOrder()