From 61f48401886e3ef15cad09461d53318285870ca2 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 18 Jan 2022 10:17:01 +0000 Subject: [PATCH] Make endianness detection more portable The current check for endianness fails on platforms using newlib as the C library, because it provides not . This could be fixed by adding `|| defined(__NEWLIB__)` to the check for targets that provide (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. --- include/fast_float/float_common.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 9374cdf..bb8580e 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -41,7 +41,9 @@ #define FASTFLOAT_VISUAL_STUDIO 1 #endif -#ifdef _WIN32 +#if defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__ +#define FASTFLOAT_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#elif defined _WIN32 #define FASTFLOAT_IS_BIG_ENDIAN 0 #else #if defined(__APPLE__) || defined(__FreeBSD__)