C++ Logo


Advanced search

Re: What even happened to <net> and byte swapping?

From: Gennaro Prota <gennaro.prota_at_[hidden]>
Date: Wed, 24 Feb 2021 17:12:17 +0100
On Fri, Feb 19, 2021 at 4:41 PM Matthew Woehlke via Std-Discussion
<std-discussion_at_[hidden]> wrote:
> I was looking at some code that needs to do byte-order swapping, and it
> seems the most portable way is still the non-standard htonX/ntohX family
> of functions.
> N3783 proposed standardizing these back in 2013(!)... but it doesn't
> seem that this ever happened. We got std::endian (finally) in C++20, but
> there do not seem to be any accompanying conversion functions.
> Am I missing something, or do we still not have a way in standard C++ to
> swap byte order of integer values?

I have worked on many applications that needed to handle different
endiannesses, but never had to swap bytes around, either in C++ or in
C#. Would something like this fit your needs:


? The unit tests may give some usage hints, although everything should
be intuitive:


.:: Gennaro Prota ::.
.:: https://about.me/gennaro ::.

Received on 2021-02-24 10:12:56