Skip to content

endian.h: Guard against __{BIG,LITTLE}_ENDIAN being defined#114

Open
bsdimp wants to merge 1 commit into
rustyrussell:masterfrom
bsdimp:branch
Open

endian.h: Guard against __{BIG,LITTLE}_ENDIAN being defined#114
bsdimp wants to merge 1 commit into
rustyrussell:masterfrom
bsdimp:branch

Conversation

@bsdimp

@bsdimp bsdimp commented May 6, 2024

Copy link
Copy Markdown

When compiled on FreeBSD, we get both __LITTLE_ENDIAN and __BIG_ENDIAN defined. glibc defines these as well, but it defines them to 1234 and
4321. However, FreeBSD defines them to ORDER_LITTLE_ENDIAN and ORDER_BIG_ENDIAN to take advantage of the recent gcc and clang predefines. Check to see if __LITTLE_ENDIAN is defined before we redefine it. This is less than perfect, I'll grant, but anything starting with __ is in the implementation namespace so some care needs to be taken.

When compiled on FreeBSD, we get both __LITTLE_ENDIAN and __BIG_ENDIAN
defined. glibc defines these as well, but it defines them to 1234 and
4321. However, FreeBSD defines them to __ORDER_LITTLE_ENDIAN__ and
__ORDER_BIG_ENDIAN__ to take advantage of the recent gcc and clang
predefines. Check to see if __LITTLE_ENDIAN is defined before we
redefine it. This is less than perfect, I'll grant, but anything
starting with __ is in the implementation namespace so some care needs
to be taken.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants