C++ Logo


Advanced search

Re: [ub] A proposal to define signed overflow submitted?

From: Myria <myriachan_at_[hidden]>
Date: Sun, 18 Feb 2018 22:15:30 -0800
C and C++'s main competitors all either define signed overflow as
wrapping or define it as trapping. Some do both, allowing the
programmer to choose situationally.

None of these languages leave it undefined to allow the
compiler/interpreter to assume that it cannot happen - it's rather
unique to C and C++. Most of these languages are considered "safer",
too. The origins of leaving the behavior undefined are because weird
things happen on non-two's-complement machines.


On Sun, Feb 18, 2018 at 9:52 PM, JF Bastien <cxx_at_[hidden]> wrote:
> On Sun, Feb 18, 2018 at 9:48 PM Lawrence Crowl <Lawrence_at_[hidden]> wrote:
>> On 2/16/18, Freek Wiedijk <freek_at_[hidden]> wrote:
>> > Is there a good reason not to have it be implementation defined
>> > whether signed overflow is undefined or wrapping?
>> If integer overflow is undefined behavior, then it is wrong. Tools can
>> detect wrong programs and report them.
>> If integer overflow is wrapping, then one never knows whether or
>> not the programmer is relying on wrapper or would be surprised at
>> wrapping. No diagnostic is possible.
> No disagreement. I wrote the paper the way I did because I want that
> discussion to conclude what the default should be, and what the more verbose
> alternate should be: UB or two’s complement?
> There are many ways we can design this. I proposed the one I find more
> palatable, expecting others to disagree.
> It would be great for a solid reasoning to emerge on the design.
> _______________________________________________
> ub mailing list
> ub_at_[hidden]
> http://www.open-std.org/mailman/listinfo/ub

Received on 2018-02-19 07:15:32