Solved What is the native endianness of my platform?
-
I have a third party library that says it returns an array of data in the native endianness of my platform. Trouble is, how do I know what the native endianness of my platform is? Is there some sort of compile time flag I can check to test this?
-
bool isBigEndian() { static const int i = 1; static bool endian= ( (*(char*)&i) == 0 ); return endian; }
https://developer.ibm.com/articles/au-endianc/
There are some Qt macros also:
Q_BIG_ENDIAN This macro represents a value you can compare to the macro Q_BYTE_ORDER to determine the endian-ness of your system. In a big-endian system, the most significant byte is stored at the lowest address. The other bytes follow in decreasing order of significance. #if Q_BYTE_ORDER == Q_BIG_ENDIAN ... #endif See also Q_BYTE_ORDER and Q_LITTLE_ENDIAN. Q_BYTE_ORDER
-
Hi, also there's a Qt class QSysInfo that has a ByteOrder enum, query it like this:
#include "qsysinfo.h" qDebug() << QSysInfo::ByteOrder;
this returns 0 on big endian platforms and 1 on little endians