ENDIAN.H(7) Miscellaneous Information Manual ENDIAN.H(7)

endian.hsystem 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.

This macro shall have a value equal to one of the *_ENDIAN macros in this header.

If BYTE_ORDER == LITTLE_ENDIAN, the host byte order is from least significant to most significant.
If BYTE_ORDER == BIG_ENDIAN, the host byte order is from most significant to least significant.

These macros shall be suitable for use in 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 , , and 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.

<stdint.h>

XSH be16toh(3), htonl(3), swab(3)

First released in Issue 8.

June 14, 2024 posix.fail