Created
December 23, 2013 01:19
-
-
Save zhaoyk/8090552 to your computer and use it in GitHub Desktop.
copy from node/src/node_internals.h
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
enum Endianness { | |
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h. | |
kBigEndian | |
}; | |
inline enum Endianness GetEndianness() { | |
// Constant-folded by the compiler. | |
const union { | |
uint8_t u8[2]; | |
uint16_t u16; | |
} u = { | |
{ 1, 0 } | |
}; | |
return u.u16 == 1 ? kLittleEndian : kBigEndian; | |
} | |
inline bool IsLittleEndian() { | |
return GetEndianness() == kLittleEndian; | |
} | |
inline bool IsBigEndian() { | |
return GetEndianness() == kBigEndian; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment