Summary:
gcc and clang both give you these three macros pre-defined. I've found a
reference on the interweb to this being broken
(http://gcc.gnu.org/ml/gcc/2011-08/msg00152.html) but that was with gcc
4.4. I've tested with 4.6, 4.7 and clang 3.2 and they all do the right
thing on little-endian (internal build and OS X). Alas, I don't have a
big-endian system handy to test with.
Test Plan: fbconfig/fbmake runtests.
Reviewed By: simpkins@fb.com
FB internal diff:
D799416
#include <cassert>
#include <cinttypes>
#include <cassert>
#include <cinttypes>
#include <iterator>
#include <limits>
#include <type_traits>
#include <iterator>
#include <limits>
#include <type_traits>
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
template <class T>
struct EndianInt : public detail::EndianIntBase<T> {
template <class T>
struct EndianInt : public detail::EndianIntBase<T> {
static T little(T x) { return x; }
};
static T little(T x) { return x; }
};
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
template <class T>
struct EndianInt : public detail::EndianIntBase<T> {
template <class T>
struct EndianInt : public detail::EndianIntBase<T> {
#else
# error Your machine uses a weird endianness!
#else
# error Your machine uses a weird endianness!
-#endif /* __BYTE_ORDER */
+#endif /* __BYTE_ORDER__ */
};
static constexpr Order order =
};
static constexpr Order order =
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Order::BIG;
#else
# error Your machine uses a weird endianness!
Order::BIG;
#else
# error Your machine uses a weird endianness!
-#endif /* __BYTE_ORDER */
+#endif /* __BYTE_ORDER__ */
template <class T> static T swap(T x) {
return detail::EndianInt<T>::swap(x);
template <class T> static T swap(T x) {
return detail::EndianInt<T>::swap(x);
#endif
#include <cstdlib>
#endif
#include <cstdlib>
#include <algorithm>
#include <limits>
#include <type_traits>
#include <algorithm>
#include <limits>
#include <type_traits>
#include "folly/Likely.h"
#include "folly/Range.h"
#include "folly/Likely.h"
#include "folly/Range.h"
-#if __BYTE_ORDER != __LITTLE_ENDIAN
+#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
#error EliasFanoCoding.h requires little endianness
#endif
#error EliasFanoCoding.h requires little endianness
#endif
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include <fcntl.h>
#include <string>
#undef EXPECTED_CLASS
// Validate ELF data encoding (LSB/MSB)
#undef EXPECTED_CLASS
// Validate ELF data encoding (LSB/MSB)
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define EXPECTED_ENCODING ELFDATA2LSB
# define EXPECTED_ENCODING ELFDATA2LSB
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define EXPECTED_ENCODING ELFDATA2MSB
#else
# error Unsupported byte order
# define EXPECTED_ENCODING ELFDATA2MSB
#else
# error Unsupported byte order
uint64_t v64 = 0x123456789abcdef0ULL;
uint64_t v64s = 0xf0debc9a78563412ULL;
uint64_t v64 = 0x123456789abcdef0ULL;
uint64_t v64s = 0xf0debc9a78563412ULL;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define GEN1(sz) \
EXPECT_EQ(v##sz, Endian::little(v##sz)); \
#define GEN1(sz) \
EXPECT_EQ(v##sz, Endian::little(v##sz)); \
EXPECT_EQ(v##sz##s, Endian::big(v##sz)); \
EXPECT_EQ(v##sz##s, Endian::big##sz(v##sz));
EXPECT_EQ(v##sz##s, Endian::big(v##sz)); \
EXPECT_EQ(v##sz##s, Endian::big##sz(v##sz));
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define GEN1(sz) \
EXPECT_EQ(v##sz##s, Endian::little(v##sz)); \
#define GEN1(sz) \
EXPECT_EQ(v##sz##s, Endian::little(v##sz)); \
#else
# error Your machine uses a weird endianness!
#else
# error Your machine uses a weird endianness!
-#endif /* __BYTE_ORDER */
+#endif /* __BYTE_ORDER__ */
#define GEN(sz) \
EXPECT_EQ(v##sz##s, Endian::swap(v##sz)); \
#define GEN(sz) \
EXPECT_EQ(v##sz##s, Endian::swap(v##sz)); \