You have to use predefined compiler macros (_BIG_ENDIAN_\__BIG_ENDIAN__
or _LITTLE_ENDIAN_\__LITTLE_ENDIAN__
with clang, or _BYTE_ORDER_\__BYTE_ORDER__
with gcc).
The other compiler macro tricks mentioned will only detect the endianness of the architecture you are compiling onon, not the endianness of the architecture you are compiling forfor, so something like this is wrong wrong:
#define IS_BIG_ENDIAN ('\x01\x02\x03\x04' == 0x01020304)
\#define IS_BIG_ENDIAN ('\x01\x02\x03\x04' == 0x01020304)