Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
deleted 8 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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)

You have to use predefined compiler macros (_BIG_ENDIAN_ or _LITTLE_ENDIAN_ with clang, or _BYTE_ORDER_ with gcc)

The other compiler macro tricks mentioned will only detect the endianness of the architecture you are compiling on, not the endianness of the architecture you are compiling for, so something like this is wrong :

#define IS_BIG_ENDIAN ('\x01\x02\x03\x04' == 0x01020304)

You have to use predefined compiler macros (\__BIG_ENDIAN__ or \__LITTLE_ENDIAN__ with clang, or \__BYTE_ORDER__ with gcc).

The other compiler macro tricks mentioned will only detect the endianness of the architecture you are compiling on, not the endianness of the architecture you are compiling for, so something like this is wrong:

\#define IS_BIG_ENDIAN ('\x01\x02\x03\x04' == 0x01020304)
Source Link
ajv
  • 21
  • 1

You have to use predefined compiler macros (_BIG_ENDIAN_ or _LITTLE_ENDIAN_ with clang, or _BYTE_ORDER_ with gcc)

The other compiler macro tricks mentioned will only detect the endianness of the architecture you are compiling on, not the endianness of the architecture you are compiling for, so something like this is wrong :

#define IS_BIG_ENDIAN ('\x01\x02\x03\x04' == 0x01020304)

Morty Proxy This is a proxified and sanitized view of the page, visit original site.