News for hackers. Stuff that matters.
Re:Falsehoods programmers believe about undefined behavior by oconnor663 on Monday November 28, 2022 @05:38PM (#33780898)
Everyone's getting confused about the word "reach". If the execution of a program triggers UB at any point then its behavior is undefined at all points, even "before" the UB was triggered. But the compiler does have to respect and preserve the behavior of any completely UB-free execution of your program, even if other executions (say with different input) could trigger UB.

So we could say, unreachable UB is fine, but if you do reach it, then it doesn't matter when you reached it.

Re:Falsehoods programmers believe about undefined behavior by leni536 on Tuesday November 29, 2022 @02:34AM (#33784675)
Point 14 explicitly says UB in dead code.

The implicit assumption is no UB in live code, otherwise the UB in dead code is a red herring.

So the UB is never reached, by the definition of dead code.

Unreachable UB is fine.

If this wasn't the intended message of point 14, then it's phrased wrong.

Re:Falsehoods programmers believe about undefined behavior by oconnor663 on Tuesday November 29, 2022 @04:10AM (#33785317)
Yeah the format of the article makes this mistake extra confusing. The statement in point 14 is in fact true, but the whole premise is that all these statements are supposed to be false.