endian.h — system endianness
#include <endian.h>
The <endian.h> header shall define at least the following macros for use in determining host byte order for integer types.
- BYTE_ORDER
- This macro shall have a value equal to one of the *_ENDIAN macros in this header.
- LITTLE_ENDIAN
If BYTE_ORDER == LITTLE_ENDIAN, the host byte order is from least significant to most significant.- BIG_ENDIAN
- If BYTE_ORDER == BIG_ENDIAN, the host byte order is from most significant to least significant.
These macros shall be suitable for use in #if preprocessing directives. The macros BIG_ENDIAN and LITTLE_ENDIAN shall have distinct values. Implementations may define other macros with the _ENDIAN suffix.
The following shall be declared as functions, or defined as macros, or both. If functions are declared, function prototypes shall be provided.
uint16_t be16toh(uint16_t); uint32_t be32toh(uint32_t); uint64_t be64toh(uint64_t);
uint16_t htobe16(uint16_t); uint32_t htobe32(uint32_t); uint64_t htobe64(uint64_t);
uint16_t htole16(uint16_t); uint32_t htole32(uint32_t); uint64_t htole64(uint64_t);
uint16_t le16toh(uint16_t); uint32_t le32toh(uint32_t); uint64_t le64toh(uint64_t);The <endian.h> header shall define the uint16_t, uint32_t, and uint64_t types as described in <stdint.h>.
Inclusion of the <endian.h> header may also make visible all symbols from <stdint.h>.
None.
Many implementations also include PDP_ENDIAN to indicate a byte ordering where each pair of bytes is swapped. If BIG_ENDIAN is defined as 4321, PDP_ENDIAN would be 3412. However, this scheme is not universal, and derives its name from an obsolete processor.
None.
First released in Issue 8.
return to top of page