Difference between revisions of "cpp/types/endian"
From cppreference.com
m (→See also: + byteswap) |
m (→Notes: + feature test macro) |
||
Line 37: | Line 37: | ||
}; | }; | ||
}} | }} | ||
+ | |||
+ | ===Notes=== | ||
+ | {{feature test macro|__cpp_lib_endian}} | ||
===Example=== | ===Example=== |
Revision as of 15:08, 31 January 2022
Defined in header <bit>
|
||
enum class endian { |
(since C++20) | |
Indicates the endianness of all scalar types:
- If all scalar types are little-endian,
std::endian::native
equalsstd::endian::little
- If all scalar types are big-endian,
std::endian::native
equalsstd::endian::big
Corner case platforms are also supported:
- If all scalar types have sizeof equal to 1, endianness does not matter and all three values,
std::endian::little
,std::endian::big
, andstd::endian::native
are the same. - If the platform uses mixed endian,
std::endian::native
equals neitherstd::endian::big
norstd::endian::little
.
Contents |
Possible implementation
enum class endian { #ifdef _WIN32 little = 0, big = 1, native = little #else little = __ORDER_LITTLE_ENDIAN__, big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ #endif };
Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_endian |
Example
Run this code
Possible output:
little-endian
See also
(C++23) |
reverses the bytes in the given integer value (function template) |