Skip to content

Commit 61f4840

Browse files
committed
Make endianness detection more portable
The current check for endianness fails on platforms using newlib as the C library, because it provides <machine/endian.h> not <endian.h>. This could be fixed by adding `|| defined(__NEWLIB__)` to the check for targets that provide <machine/endian.h> (i.e. BSD-like targets). A more portable solution is to just check if the compiler has already defined the necessary macros (which is true for GCC and Clang and Intel, at least). Then no header is needed, and it works for platforms that aren't explicitly listed in the conditionals.
1 parent b15abc9 commit 61f4840

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/fast_float/float_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
#define FASTFLOAT_VISUAL_STUDIO 1
4242
#endif
4343

44-
#ifdef _WIN32
44+
#if defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__
45+
#define FASTFLOAT_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
46+
#elif defined _WIN32
4547
#define FASTFLOAT_IS_BIG_ENDIAN 0
4648
#else
4749
#if defined(__APPLE__) || defined(__FreeBSD__)

0 commit comments

Comments
 (0)