diff options
author | Chris Robinson <[email protected]> | 2021-01-06 18:04:04 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-01-06 18:04:04 -0800 |
commit | 1f24f5caa1c5370b942938d714cf203f5564de7c (patch) | |
tree | 45707dc9f31b8472588c3e923a5f07537cd5a8a5 /common/endiantest.h | |
parent | 948ae3bc7e1e8a1b29b8e78388d1479f5b7a4758 (diff) |
Ensure the endian test is constexpr
Diffstat (limited to 'common/endiantest.h')
-rw-r--r-- | common/endiantest.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/common/endiantest.h b/common/endiantest.h index 0a20eb91..893653bd 100644 --- a/common/endiantest.h +++ b/common/endiantest.h @@ -4,11 +4,12 @@ #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) #define IS_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) #else -static const union { - unsigned int u; - unsigned char b[sizeof(unsigned int)]; -} EndianTest = { 1 }; -#define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1) +constexpr inline bool EndianTest() noexcept +{ + constexpr int test_val{1}; + return static_cast<const char&>(test_val); +} +#define IS_LITTLE_ENDIAN (EndianTest()) #endif #endif /* AL_ENDIANTEST_H */ |