ipaddress 1.1.0
Loading...
Searching...
No Matches
endian.hpp File Reference

Defines macros to determine byte order. More...

#include "config.hpp"

Go to the source code of this file.

Namespaces

namespace  ipaddress
 Namespace dedicated to IP addresses and networks operations.
 

Functions

constexpr inline bool is_little_endian () noexcept
 Checks if the system is little-endian.
 
constexpr inline uint32_t swap_bytes (uint32_t value) noexcept
 Swaps the bytes of a 32-bit unsigned integer.
 

Detailed Description

Defines macros to determine byte order.

Author
Vladimir Shaleev

This header file contains macros and utility functions to determine and work with the byte order (endianness) of the system. It provides a set of preprocessor directives that establish the byte order based on various conditions, such as user definitions, C++20 standard features, or platform-specific macros.

The file defines IPADDRESS_LITTLE_ENDIAN and IPADDRESS_BIG_ENDIAN as constants for comparison and sets IPADDRESS_ENDIAN accordingly. It also includes functions to check the system's endianness and to swap bytes in an integer, which are useful for network programming and handling data with different endianness.

The determination of endianness is done with a priority order:

  1. C++20's std::endian.
  2. User-defined IPADDRESS_ENDIAN.
  3. Platform/compiler-provided macros.

If the endianness cannot be determined, a compilation error is raised prompting the user to define IPADDRESS_ENDIAN.