Possible Duplicate:
Detecting endianness programmatically in a C++ program
I'm trying to check if I'm running a little or big endian OS.
int main()
{
int i = 1;
unsigned char b = i;
char *c = reinterpret_cast<char*>(&i); // line 5
cout << "Processor identified as: " << endl;
if (*c == b)
cout << "Little endian" << endl;
else
cout << "Big endian" << endl;
}
I'm not sure if casting an int*
to char*
pointer in line 5 is guaranteed to return a lowest address. Am I doing it right?