lefticus / cpp_weekly

The official C++ Weekly Repository. Code samples and notes of future / past episodes will land here at various times. PR's will be accepted in some cases.
The Unlicense
698 stars 26 forks source link

[C++ weekly]: My wishlist : packing + endianess #353

Open AncalagonTotof2 opened 8 months ago

AncalagonTotof2 commented 8 months ago

Channel

C++Weekly"

Topics

I'd like to learn about packing and endianess. I'm using these in embedded context, mostly in C, rarely in C++. Usually to fit data in very limited amounts of RAM or Flash; or to transmit data over a link, bus or network. Anyway, I'm doing it the old way, with #prama pack or something. I wonder if there is some other way to do it.

Length

You tell me ... I'd say it will depend on the question "is there some other way to do it ?" I've been surprise to discover that there is an std::something for alignments. I would be surprise if there's nothing for packing and endianess ...

JohelEGP commented 8 months ago

There's Boost.Endian (https://www.boost.org/doc/libs/release/libs/endian/doc/html/endian.html) and std::endian (https://en.cppreference.com/w/cpp/types/endian).