Official boost macro to determine endianess?
What is the official boost macro to determine endianess? And what is the header to include to get it? I cannot find any help in the documentation of boost.endian but I can find those macros by grepping in boost: BOOST_LITTLE_ENDIAN, BOOST_BIG_ENDIAN, BOOST_ENDIAN_BIG_BYTE, BOOST_ENDIAN_BIG_WORD, BOOST_ENDIAN_LITTLE_BYTE, BOOST_ENDIAN_LITTLE_WORD, BOOST_PDP_ENDIAN Thanks, Frédéric
On 04/05/17 12:00, Frédéric Bron via Boost wrote:
What is the official boost macro to determine endianess? And what is the header to include to get it?
I cannot find any help in the documentation of boost.endian but I can find those macros by grepping in boost:
BOOST_LITTLE_ENDIAN, BOOST_BIG_ENDIAN, BOOST_ENDIAN_BIG_BYTE, BOOST_ENDIAN_BIG_WORD, BOOST_ENDIAN_LITTLE_BYTE, BOOST_ENDIAN_LITTLE_WORD, BOOST_PDP_ENDIAN
I think the modern way to do this is to use Boost.Predef[1]. BOOST_LITTLE_ENDIAN, BOOST_BIG_ENDIAN and BOOST_PDP_ENDIAN predate Boost.Predef and are deprecated. [1]: http://www.boost.org/doc/libs/1_63_0/doc/html/predef/reference.html#predef.r...
I think the modern way to do this is to use Boost.Predef.
Great, thanks! By the way, why does the predef library not follow the boost policy [1] on file names, i.e. saying that header files should have .hpp extension and not .h? [1] http://www.boost.org/development/header.html
-----Original Message----- From: Boost [mailto:boost-bounces@lists.boost.org] On Behalf Of Andrey Semashev via Boost Sent: 05 April 2017 10:25 To: boost@lists.boost.org Cc: Andrey Semashev Subject: Re: [boost] Official boost macro to determine endianess?
On 04/05/17 12:00, Frédéric Bron via Boost wrote:
What is the official boost macro to determine endianess? And what is the header to include to get it?
I cannot find any help in the documentation of boost.endian but I can find those macros by grepping in boost:
BOOST_LITTLE_ENDIAN, BOOST_BIG_ENDIAN, BOOST_ENDIAN_BIG_BYTE, BOOST_ENDIAN_BIG_WORD, BOOST_ENDIAN_LITTLE_BYTE, BOOST_ENDIAN_LITTLE_WORD, BOOST_PDP_ENDIAN
I think the modern way to do this is to use Boost.Predef[1].
BOOST_LITTLE_ENDIAN, BOOST_BIG_ENDIAN and BOOST_PDP_ENDIAN predate Boost.Predef and are deprecated.
[1]: http://www.boost.org/doc/libs/1_63_0/doc/html/predef/reference.html#predef.r...
That the question was asked sadly shows that our methods of finding Boost things are still not good? Searching boost.org from the front page does not provide any links to Boost.Predef, only Boost.Endian. Or does it mean that Boost.Endian documentation should draw attention to the existence of Boost.Predef? --- Paul A. Bristow Prizet Farmhouse Kendal UK LA8 8AB +44 (0) 1539 561830 Paul
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 <boost/predef.h> 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= "<<std::setw(4)<<value<<'\n'; auto c = reinterpret_cast<const std::uint8_t *>(&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; }
Sorry, I should not have used #elif, in fact ALL macros are defined! BOOST_ENDIAN_BIG_BYTE BOOST_ENDIAN_BIG_WORD BOOST_ENDIAN_LITTLE_BYTE BOOST_ENDIAN_LITTLE_WORD What does this mean? I see that g++ has #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ Frédéric 2017-04-05 14:23 GMT+02:00 Frédéric Bron <frederic.bron@m4x.org>:
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 <boost/predef.h>
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= "<<std::setw(4)<<value<<'\n';
auto c = reinterpret_cast<const std::uint8_t *>(&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; }
On Wed, Apr 5, 2017 at 11:00 AM, Frédéric Bron via Boost <boost@lists.boost.org> wrote:
What is the official boost macro to determine endianess? And what is the header to include to get it?
I cannot find any help in the documentation of boost.endian but I can find those macros by grepping in boost:
BOOST_LITTLE_ENDIAN, BOOST_BIG_ENDIAN, BOOST_ENDIAN_BIG_BYTE, BOOST_ENDIAN_BIG_WORD, BOOST_ENDIAN_LITTLE_BYTE, BOOST_ENDIAN_LITTLE_WORD, BOOST_PDP_ENDIAN
Shouldn't functions from the endian lib be used? -- Olaf
On Wed, Apr 5, 2017 at 1:51 PM, Frédéric Bron <frederic.bron@m4x.org> wrote:
Shouldn't functions from the endian lib be used?
but there is no documentation about them (or I missed it).
http://www.boost.org/doc/libs/1_63_0/libs/endian/doc/ What are you trying to do? -- Olaf
Shouldn't functions from the endian lib be used?
but there is no documentation about them (or I missed it).
yes no documentation for the endian macros and I did not find anywhere in this page how to know the actual endianess.
What are you trying to do?
I need to know the endianess type for a cryptographic algorithm. Frédéric
participants (4)
-
Andrey Semashev
-
Frédéric Bron
-
Olaf van der Spek
-
Paul A. Bristow