I think the modern way to do this is to use Boost.Predef[1].
I used predef in a small program (see below) but I'm surprised by the output:
BOOST_ENDIAN_BIG_BYTE
value= 0102
memory=0201
predef says I am big endian but I see that most significant byte
(0x01) is stored at the end which seems to indicate little endian.
My processor is: Intel(R) Core(TM) i7-6700HQ
Frédéric
Program:
#include <cstdint>
#include <iomanip>
#include <iostream>
#include
int main() {
#if defined(BOOST_ENDIAN_BIG_BYTE)
std::cerr << "BOOST_ENDIAN_BIG_BYTE\n";
#elif defined(BOOST_ENDIAN_BIG_WORD)
std::cerr << "BOOST_ENDIAN_BIG_WORD\n";
#elif defined(BOOST_ENDIAN_LITTLE_BYTE)
std::cerr << "BOOST_ENDIAN_LITTLE_BYTE\n";
#elif defined(BOOST_ENDIAN_LITTLE_WORD)
std::cerr << "BOOST_ENDIAN_LITTLE_WORD\n";
#endif
std::cout << std::hex << std::setfill('0');
std::uint16_t value = 0x0102;
std::cout<<"value= "<(&value);
std::cout<<"memory=";
for (int i = 0; i < (int)sizeof(value); ++i) {
std::cout << std::setw(2) << static_cast<int>(c[i]);
}
std::cout << '\n';
return 0;
}