Thrill  0.1
endian.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/define/endian.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2018 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_DEFINE_ENDIAN_HEADER
12 #define TLX_DEFINE_ENDIAN_HEADER
13 
14 namespace tlx {
15 
16 //! \addtogroup tlx_define
17 //! \{
18 
19 // borrowed from https://stackoverflow.com/a/27054190
20 
21 #if (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) || \
22  (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
23  defined(__BIG_ENDIAN__) || \
24  defined(__ARMEB__) || \
25  defined(__THUMBEB__) || \
26  defined(__AARCH64EB__) || \
27  defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
28 
29 // It's a big-endian target architecture
30 #define TLX_BIG_ENDIAN 1
31 
32 #elif (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
33  (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
34  defined(__LITTLE_ENDIAN__) || \
35  defined(__ARMEL__) || \
36  defined(__THUMBEL__) || \
37  defined(__AARCH64EL__) || \
38  defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \
39  defined(_MSC_VER)
40 
41 // It's a little-endian target architecture
42 #define TLX_LITTLE_ENDIAN 1
43 
44 #else
45 #error "tlx: I don't know what architecture this is!"
46 #endif
47 
48 //! \}
49 
50 } // namespace tlx
51 
52 #endif // !TLX_DEFINE_ENDIAN_HEADER
53 
54 /******************************************************************************/