C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Validity of conversions between 4 byte-like types (byte, char) objects
From: Roman Babinicz (rb_at_[hidden])
Date: 2019-12-11 12:09:49


On 11/12/2019 17:26, Thiago Macieira wrote:

> Pre-C++17:
> The integer conversions are very well explained in the standard. Converting
> from signed to unsigned is such that any non-negative values retain their
> values and any negative ones are represented as TYPE_MAX + 1 -
> absolute(value).

Thanks,

in e.g. C++14, which points of standard define the negative values as
above to be converted into TYPE_MAX + 1 - absolute(value) ?

It was my understanding that the converted value in such case depends on
the binary representation of negative integers, and it would be as you
written on platforms with 2's complement - but could differ on others.

C++14 4.7(.2) [conv.integral] mentions what would happen in two's
complement representation - but that "Note" text seems to only apply to
situation in which we know that the two's complement is used for the
signed type.
And in C++14 that is not guaranteed afaik.

Which is why I thought that for some values it is implementation defined
what will be the result of assigning signed int into unsigned int.


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups