C++ Logo

sg12

Advanced search

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

From: Hyman Rosen <hyman.rosen_at_[hidden]>
Date: Wed, 14 Mar 2018 14:55:19 -0400
On Wed, Mar 14, 2018 at 2:23 PM, Lawrence Crowl <Lawrence_at_[hidden]> wrote:

> On 3/14/18, Hyman Rosen <hyman.rosen_at_[hidden]> wrote:
> > On Mar 14, 2018, Lawrence Crowl <Lawrence_at_[hidden]> wrote:
> Second, and most imporant, C's pointer and array model enabled
> programmers to write in source code the kinds of optimizations that
> compilers of the day were not doing. In particular, compilers were
> not doing strength reduction in loops. In practice, a C program
> could run in half the time of a Pascal program. Consequently, the
> need for using assembler was lower, which avoided the significant
> cost of writing in assembler. That optimization ability is exactly
> why C became popular.
>

Notice that this is an optimization *written by the programmer*.

The most popular quote about C back in the day was "trust the programmer."
The notion that parts of a program should be ignored because the compiler
decides their behavior is undefined and therefore don't run is antithetical
to that.

The language has undefined behavior because it was targeted to systems
> in which instruction sets did radically different things.


But each of those systems did *something*. The compiler world generate the
obvious (remember, transparency) instructions corresponding to the code,
and the program would get whatever the result was. There was never a
notion that undefined behavior gave the compiler permission to act as if the
program never executed undefined behavior.

As usual, Ada was on top of this. Ada95 defined the concept of bounded
error
<http://www.adaic.org/resources/add_content/standards/95rat/rat95html/rat95-p2-1.html#4>
:

*The general idea is that the behavior is not fully determined but
neverthelessfalls within well-defined bounds.*

Compiler writers are often under intense pressure to squeeze more
> performance out of programs. They have made legal code faster at the
> expense of illegal programs. In doing so, they did not change the
> language. On the surface, that is reasonable. The major problem was
> that they started performing an entirely new class of optimizations
> without warning anyone.


The fundamental error is claiming that undefined behavior constitutes an
"illegal program", or rather, that behavior which may not be definable in
the
same way in every environment should constitute an illegal program. It's
my contention that the optimizationist sect of compiler writers are the
people
who pushed for making such unportable programs illegal to begin with.

I have no sympathy for people who press to get the wrong answer faster.
It's the patricide asking for mercy as an orphan here.

Received on 2018-03-14 19:55:43