News for hackers. Stuff that matters.
Re:C and C++ Prioritize Performance over Correctness by _dain_ on Friday August 18, 2023 @03:01PM (#37180495)
>You've made an obviously non-sensical statement—

Therefore it should fail to compile.

You can even spin it as a performance enhancement: the whole program can be optimized away!

Re:C and C++ Prioritize Performance over Correctness by layer8 on Friday August 18, 2023 @03:32PM (#37180918)
The problem is, that’s not how the logical inference in a compiler/optimizer works. It’s very difficult to translate such an optimization back to “this statement has been optimized away”, in the general case.
Re:C and C++ Prioritize Performance over Correctness by _dain_ on Friday August 18, 2023 @03:36PM (#37180994)
If it's so difficult to figure out if the consequences of their optimization game are sensible or not, then they shouldn't play it in the first place.

Who actually wants it to behave this way, other than compiler engineers competing on microbenchmarks? Who is this language even for?

Re:C and C++ Prioritize Performance over Correctness by layer8 on Friday August 18, 2023 @03:40PM (#37181027)
It’s a side effect of desirable optimizations for UB-free code. You can’t have both at the same time.
Re:C and C++ Prioritize Performance over Correctness by _dain_ on Friday August 18, 2023 @03:48PM (#37181131)
Desirable for whom? Are the beneficiaries of it going to pay for the externalities they are generating, like polluters should?

You can say "ordinary workaday programmers benefit from speed improvements en passant", but they weren't really given a choice in the matter, were they? When programmers are given an explicit binary choice of "correct, but slightly slower", and "wrong, but slightly faster", they pick the former in practically all cases (or they should, at any rate). But they can't make this choice; the compiler and spec writers go behind their backs and construct these inscrutable labyrinths, then blame everyone else for getting lost in them.

Re:C and C++ Prioritize Performance over Correctness by aidenn0 on Saturday August 19, 2023 @01:18AM (#37185761)
-fwrapv is there for people to use. People don't use it.

Yes defaults matter, but they matter both ways. People benchmark with the default options and a compiler with -fwrapv turned on by default will lose those benchmarks and the "ordinary workaday programmers" still end up with trading correctness for speed, since one person at their workplace ran one benchmark once and picked the compiler that won in speed.