The Open Group Base Specifications Issue 8
IEEE Std 1003.1-2024
Copyright © 2001-2024 The IEEE and The Open Group

NAME

endian.h — system endianness

SYNOPSIS

#include <endian.h>

DESCRIPTION

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


The following sections are informative.

APPLICATION USAGE

None.

RATIONALE

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.

FUTURE DIRECTIONS

None.

SEE ALSO

<stdint.h>

XSH be16toh, htonl, swab

CHANGE HISTORY

First released in Issue 8.

End of informative text.

 

return to top of page

UNIX® is a registered Trademark of The Open Group.
POSIX™ is a Trademark of The IEEE.
Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved
[ Main Index | XBD | XSH | XCU | XRAT ]