Re: signed int overflow

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 09/20/04


Date: Mon, 20 Sep 2004 11:42:57 +0200

JKop wrote:

>
> Okay let's say that Standard C++... allows... a program to crash should
> you cause a signed int to overflow.
>
> Well... what the hell kind of implementation would allow this?! Even if
> one does exist, it would have been abandoned 17 years 6 months and 2 days
> ago.

Why do you think a CPU that silently ignores overflows would be better than
one that signals such an error condition?
Anyway, a crash is not the only instance of undefined behavior. Another
could be an exception being thrown. However, if you don't catch that
exception, the result is similar to a crash - your program gets terminated.
AFAIK, there are implementations that throw an exception on a
division-by-zero, and I could imagine that there could be implementations
that throw on integer overflow.

> Imagine it, boot up WinXP. Open a few documents, play minesweeper, CRASH
> (Opps sorry, this computer is ***, it crashes if signed integers
> overflow).

Then you could also say minesweeper is *** because it invokes undefined
behavor.

> I'm open to further discussion on this... but at the moment it looks like
> I'm going to ignore the directive that signed int overflow is undefined
> behaviour and thus that the program may crash. Come on, it's bull***!

I don't really get it. You want to overflow an integer and don't care for
the resulting value as long as you don't get a crash? What is the purpose
of that integer if the value doesn't matter?