Re: [PATCH v2 2/6] bswap.h: Add support for __BYTE_ORDER__
- From
Collin Funk <collin.funk1@gmail.com>
- Date
- Jun 12, 2025, 00:43 UTC
- Message-ID
- <87wm9hkcvr.fsf@gmail.com>
- In-Reply-To
- <aEoeUCcXYByjU5HR@fruit.crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 9 quoted lines
> One additional option you can add if you want (it's completely optional) > is that if `__STDC_VERSION__` is 202311L or larger, then you can > `#include <stdbit.h>`, which has `__STDC_ENDIAN_LITTLE__`, > `__STDC_ENDIAN_BIG__`, and `__STDC_ENDIAN_NATIVE__`. > > That will work on a modern GCC or clang with an appropriate compiler > flag. I don't know about MSVC, but it might be an option for people who > want to use more esoteric compilers which support standards but aren't > very compatible with GCC and clang.
Another standard that is too new to be common, but POSIX.1-2024 added <endian.h> with BYTE_ORDER, LITTLE_ENDIAN, and BIG_ENDIAN [1].
In practice, some systems will have it because glibc had it for a long time.
Collin
[1] https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/endian.h.html