Skip to content

Commit 78f622e

Browse files
committed
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.
1 parent 9a48c87 commit 78f622e

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

include/fpmath.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,37 @@
3838
#endif
3939
#endif
4040

41-
#ifdef __linux
41+
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
42+
43+
/* Definitions provided directly by GCC and Clang. */
44+
#define _LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
45+
#define _BIG_ENDIAN __ORDER_BIG_ENDIAN__
46+
#define _PDP_ENDIAN __ORDER_PDP_ENDIAN__
47+
#define _BYTE_ORDER __BYTE_ORDER__
48+
49+
#elif defined(__linux)
50+
4251
#include <features.h>
4352
#include <endian.h>
4453
#define _LITTLE_ENDIAN __LITTLE_ENDIAN
4554
#define _BIG_ENDIAN __BIG_ENDIAN
4655
#define _PDP_ENDIAN __PDP_ENDIAN
4756
#define _BYTE_ORDER __BYTE_ORDER
48-
#endif
4957

50-
#ifdef __APPLE__
58+
#elif defined(__APPLE__)
59+
5160
#include <machine/endian.h>
5261
#define _LITTLE_ENDIAN LITTLE_ENDIAN
5362
#define _BIG_ENDIAN BIG_ENDIAN
5463
#define _PDP_ENDIAN PDP_ENDIAN
5564
#define _BYTE_ORDER BYTE_ORDER
56-
#endif
5765

58-
#ifdef __FreeBSD__
66+
#elif defined(__FreeBSD__)
67+
5968
#include <machine/endian.h>
60-
#endif
6169

62-
#ifdef _WIN32
70+
#elif defined(_WIN32)
71+
6372
#define _LITTLE_ENDIAN 1234
6473
#define _BIG_ENDIAN 4321
6574
#define _PDP_ENDIAN 3412
@@ -69,6 +78,7 @@
6978
#define BIG_ENDIAN _BIG_ENDIAN
7079
#define PDP_ENDIAN _PDP_ENDIAN
7180
#define BYTE_ORDER _BYTE_ORDER
81+
7282
#endif
7383

7484
#ifndef _IEEE_WORD_ORDER

0 commit comments

Comments
 (0)