2

Considering the possible implementation here:

enum class endian
{
#ifdef _WIN32
    little = 0,
    big    = 1,
    native = little
#else
    little = __ORDER_LITTLE_ENDIAN__,
    big    = __ORDER_BIG_ENDIAN__,
    native = __BYTE_ORDER__
#endif
};

Is it sure that

__ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__, __BYTE_ORDER__ 

are defined in other platforms than WIN32?

Before C++20 is released, is it possible to define such an enum for endianness? Otherwise, how to do it properly?

FlashMcQueen
  • 635
  • 3
  • 13
  • You may want to take a look at [boost endian](https://www.boost.org/doc/libs/1_68_0/libs/endian/doc/conversion.html) – user7860670 Nov 28 '18 at 13:43
  • Is it possible? Sure, but I'm seeing a similar enum in [boost](https://www.boost.org/doc/libs/1_68_0/libs/endian/doc/conversion.html) so maybe that would do? – Borgleader Nov 28 '18 at 13:43
  • The "possible implementation" is not a standardized or otherwise official way of implementing the enumeration. Instead it depends a *lot* on the compiler used and its corresponding standard library parts. What is shown is only a *possibility*, an *example* without any basis on real implementations. – Some programmer dude Nov 28 '18 at 13:43
  • 1
    for gcc see here: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html – 463035818_is_not_an_ai Nov 28 '18 at 13:43
  • 1
    This is going to compiler dependent. If you need something poratable use [Boost.Endian](https://www.boost.org/doc/libs/1_63_0/libs/endian/doc/index.html) – NathanOliver Nov 28 '18 at 13:44
  • @user463035818 but I am wondering if those macro are garanteed to be defined. – FlashMcQueen Nov 28 '18 at 13:44
  • 1
    They are not. `std::endian` is the guaranteed interface. However your implementation implements it is up to them. – NathanOliver Nov 28 '18 at 13:46
  • That's my question thank you – FlashMcQueen Nov 28 '18 at 13:49
  • the macros used in the example are those defined for gcc. For other compilers you have to check their documentation – 463035818_is_not_an_ai Nov 28 '18 at 13:59

0 Answers0