Quantcast

Official boost macro to determine endianess?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Official boost macro to determine endianess?

Boost - Dev mailing list
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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
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.reference.other_macros.boost_endian



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
> 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
Sent this privately by accident. Again.

On 04/05/17 13:14, Andrey Semashev wrote:

> On 04/05/17 12:45, Frédéric Bron wrote:
>>> 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?
>
> Because it is also usable from C.
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
On Wed, Apr 5, 2017 at 11:00 AM, Frédéric Bron via Boost
<[hidden email]> 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
> Shouldn't functions from the endian lib be used?

but there is no documentation about them (or I missed it).

Frédéric

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list


> -----Original Message-----
> From: Boost [mailto:[hidden email]] On Behalf Of Andrey Semashev via Boost
> Sent: 05 April 2017 10:25
> To: [hidden email]
> 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.reference.other_macros.boost_endian

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




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
> 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;
}

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
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 <[hidden email]>:

>> 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;
> }

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
On Wed, Apr 5, 2017 at 1:51 PM, Frédéric Bron <[hidden email]> 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
>>> 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/

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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
Re-posting.

On 04/05/17 16:51, Andrey Semashev wrote:

> On 04/05/17 15:29, Frédéric Bron wrote:
>> 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?
>
> That's how Boost.Predef works:
>
> http://www.boost.org/doc/libs/1_63_0/doc/html/predef/using_the_predefs.html
>
> You should check the macro values instead of testing if they are defined
> (i.e. use #if instead of #ifdef).
>
> Also, please, don't top-post.
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Official boost macro to determine endianess?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
> You should check the macro values instead of testing if they are defined
> (i.e. use #if instead of #ifdef).

Oh thanks, I have to check if it is positive.
Now I get the right BOOST_ENDIAN_LITTLE_BYTE (the only one positive).

Frédéric

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Loading...