Boost logo

Boost :

Subject: Re: [boost] [endian] Project not maintained
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-04-03 21:58:34


On 4/04/2016 02:21, Beman Dawes wrote:
> The new plan is to go ahead with an Endian proposal to the C++ committee.
> They have the expertise to know whether it is even possible to convert
> between big and little endian floating point in any useful (and
> non-dangerous) way.

If you have API that can take a void* or char* (or other
block-of-bytes-of-appropriate-size) and then reinterpret this as a
big-endian or little-endian float/double/longdouble (returning the
native representation), then this can work and is a useful function.
Similarly taking a native float/double/longdouble and writing it to a
block-of-bytes in a specified endian format.

If you have an API that takes a float/double/longdouble that was already
set with the "wrong" endian and you want to byteswap it, then this
cannot work and is a bad API. (This was the problem with the prior
version, IIRC.)

As a Boost.Endian library user, until the first style of API is
implemented you can work around it by doing endian swaps on unsigned
integers only, and using a bitwise_cast-equivalent to convert between
the floating-point values and unsigned integers of appropriate size.

(Although bitwise_cast is itself a debated topic, since doing it via
unions typically has better codegen but is technically UB, and doing it
without unions can get you into strict aliasing trouble if you're not
careful.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk