Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use __LITTLE_ENDIAN__ to determine endianness #7

Open
bentorkington opened this issue Jan 23, 2023 · 2 comments
Open

Don't use __LITTLE_ENDIAN__ to determine endianness #7

bentorkington opened this issue Jan 23, 2023 · 2 comments

Comments

@bentorkington
Copy link
Owner

bentorkington commented Jan 23, 2023

More reliable to use #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

@bentorkington
Copy link
Owner Author

see this gcc bug

Because it is redundant with __BYTE__ORDER__ == __LITTLE_ENDIAN__ (etc.)
And, portable apps should use
#include <endian>
#if BYTE_ORDER == LITTLE_ENDIAN
anyway.  Note that __LITTLE_ENDIAN__ etc. is then fairly ambiguous, because it looks like a special version of LITTLE_ENDIAN macro, but has completely different meaning.  And it is unclear from it what is little endian, whether bytes, words, floating point value bytes.

@bentorkington
Copy link
Owner Author

bentorkington commented Jan 25, 2023

also this s/o answer

Test the endianness with #if __BYTE_ORDER == __LITTLE_ENDIAN and #elif __BYTE_ORDER == __BIG_ENDIAN. And generate an #error elsewise

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

No branches or pull requests

1 participant