Boost logo

Boost :

Subject: Re: [boost] Current Guidance on Compiler Warnings?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2018-11-24 23:09:11

On Sat, Nov 24, 2018 at 11:07 AM Daniela Engert via Boost <
boost_at_[hidden]> wrote:
> Am 24.11.2018 um 19:48 schrieb Emil Dotchevski via Boost:
> >
> > The problem with signed/unsigned mismatch is not just in the comparison,
> > but also in the operations. If unsigned x=2, the expression x-3 may not
> > meaningfully represented by an unsigned integer.
> Au contraire, mon ami! Unsigned arithmetic is defined in C++ as an
> abelian ring modulo a value depending on the width of the given unsigned
> type. In fact, unsigned types are the only useful types if you need
> well-defined mathematical properties (like I do when it comes to digital
> signal processing).

Yes, I am aware that unsigned types have defined standard behavior when
wrapping around while with signed ints this is implementation-defined (btw
in signal processing sometimes you want saturation -- which is a valid
implementation for signed operations -- instead of wrapping).

But that's not what I mean. I mean that if you have unsigned x=2 and int y,
the expression x-3<y will not work correctly, even though x<y could
theoretically be "fixed".

But all that is besides the point which still is that, as a matter of fact,
casts are not equivalent to implicit conversions, and programmers should
choose the correct operation even if that results in a warning under -Wall.

Boost list run by bdawes at, gregod at, cpdaniel at, john at