News for hackers. Stuff that matters.
Re:Falsehoods programmers believe about undefined behavior by victor82 on Monday November 28, 2022 @07:25AM (#33772745)
It is not explained why points 31 to 36 are valid, unlike HDL synthesis tools, C compilers are pretty deterministic, same input same output, except timestamps, etc.

If an UB adopt X behavior one time, a reproducible build will take same X behavior the next time.

Of course I am not negating the fact that this undefined in the first instance nor condoning the UB usage.

Re:Falsehoods programmers believe about undefined behavior by sokoloff on Monday November 28, 2022 @07:33AM (#33772807)
That is the observed behavior of the compiler not the defined behavior. (and while there’s some logical reason to assume that will likely continue to hold, the list is falsehoods programmers believe about undefined behavior, not observed behavior.)
Re:Falsehoods programmers believe about undefined behavior by victor82 on Monday November 28, 2022 @07:39AM (#33772859)
"but it worked fine before" talks about the observed behavior
Re:Falsehoods programmers believe about undefined behavior by sokoloff on Monday November 28, 2022 @07:41AM (#33772880)
Yes. That is the sub-category of “among all the falsehoods about UB, these are the falsehoods that can be categorized as [improper reliance on] OB”.
Re:Falsehoods programmers believe about undefined behavior by obi1kenobi on Monday November 28, 2022 @12:46PM (#33776781)
(Post author here.) Agreed with the parent comment. To restate the same thing in another way in the hope of avoiding confusion:

It isn't a bug in the compiler if the compiler is non-deterministic in the presence of UB. Such behavior does not violate any guarantee provided by the compiler or language spec.

In fact, it's still not a bug if the compiler is non-deterministic, full stop. Many (most?) compilers have non-deterministic behavior due to a variety of factors. To get a sense of what's involved in getting determinism, look up some articles on why it's difficult to get reproducible builds working. It's a lot harder than it might seem at first.

Re:Falsehoods programmers believe about undefined behavior by gpderetta on Tuesday November 29, 2022 @06:17AM (#33786131)
Determinism is a QoI issue. It is an important QoI feature though and I think most compilers meant for production use at least strive to implement it. I guess things like parallel, distributed compilation make it quite hard.
Re:Falsehoods programmers believe about undefined behavior by cesarb on Monday November 28, 2022 @07:50AM (#33772975)
> C compilers are pretty deterministic, same input same output, except timestamps, etc.

"Sometimes gcc will opt to use a randomized model to guess branch probabilities, when none are available from either profiling feedback (-fprofile-arcs) or __builtin_expect. This means that different runs of the compiler on the same program may produce different object code." (from the gcc manual)

Re:Falsehoods programmers believe about undefined behavior by dooglius on Monday November 28, 2022 @08:55AM (#33773660)
Looked into this and it appears it was not the case; the docs were confusingly written, and the docs appear to have been rewritten some time ago

https://marc.info/?l=gcc&m=102068997020453&w=2

Re:Falsehoods programmers believe about undefined behavior by pavon on Monday November 28, 2022 @12:24PM (#33776420)
I was curious about that as well. If it is just an extension of 37-40, then that makes sense - since UB may or may not effect different runs of the same executable, then certainly the same is true of different runs on different builds of the same executable. But that is a confusing way to put it - it sounds like it is saying that reproducible builds are not possible, which I am skeptical of.