From 78f622e84a2a49242a2686f10e9d0e0ce1805018 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:33:54 +0100 Subject: [PATCH] Use endianness definitions provided by GCC or Clang if available. Instead of using all sorts of operating system specific constructs, we can just query the compiler which byte order is being used. This has the advantage that the code builds on new platforms without any tweaks. --- include/fpmath.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/fpmath.h b/include/fpmath.h index 3b06b7e..5698b96 100644 --- a/include/fpmath.h +++ b/include/fpmath.h @@ -38,28 +38,37 @@ #endif #endif -#ifdef __linux +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) + +/* Definitions provided directly by GCC and Clang. */ +#define _LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#define _BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#define _PDP_ENDIAN __ORDER_PDP_ENDIAN__ +#define _BYTE_ORDER __BYTE_ORDER__ + +#elif defined(__linux) + #include #include #define _LITTLE_ENDIAN __LITTLE_ENDIAN #define _BIG_ENDIAN __BIG_ENDIAN #define _PDP_ENDIAN __PDP_ENDIAN #define _BYTE_ORDER __BYTE_ORDER -#endif -#ifdef __APPLE__ +#elif defined(__APPLE__) + #include #define _LITTLE_ENDIAN LITTLE_ENDIAN #define _BIG_ENDIAN BIG_ENDIAN #define _PDP_ENDIAN PDP_ENDIAN #define _BYTE_ORDER BYTE_ORDER -#endif -#ifdef __FreeBSD__ +#elif defined(__FreeBSD__) + #include -#endif -#ifdef _WIN32 +#elif defined(_WIN32) + #define _LITTLE_ENDIAN 1234 #define _BIG_ENDIAN 4321 #define _PDP_ENDIAN 3412 @@ -69,6 +78,7 @@ #define BIG_ENDIAN _BIG_ENDIAN #define PDP_ENDIAN _PDP_ENDIAN #define BYTE_ORDER _BYTE_ORDER + #endif #ifndef _IEEE_WORD_ORDER