Possible Duplicate:
Detecting endianness programmatically in a C++ program
C Macro definition to determine big endian or little endian machine?
Currently, I have the following function to detect the system endianness :
inline bool detectSystemEndianness()
{
int i = 1;
char *c = reinterpret_cast<char*>(&i);
return (c[0] != i);
}
It returns false
if little endian, true
if big endian. First question : is this function ok ?
Second question : Instead of this function, I would like to initialize a static variable :
static bool _systemEndianness = /* SOMETHING */
How to do that ? (it has to be done at execution-time and not at compile-time ... at least I think so)