News for hackers. Stuff that matters.
Re:GCC and Clang handle statically known undefined behaviour by shadowgovt on Tuesday June 25, 2024 @10:01AM (#40788751)
I mean, I "fix my code" by avoiding languages with a lot of UB like the plague. I don't think writing a million lines of UB-free C++ is a human-shaped problem. We can pretend this is just a "skill issue," but even if it is it's a skill issue that's endemic to the industry (https://cwe.mitre.org/data/definitions/758.html), so unless you're working on a project solo you're going to come across code that has UB and it's going to be your problem to fix it.

Given that, plus the reality that we insist on continuing to write a million lines of C++, treating UB as something you'll see frequently in your career is probably the reality-based behavior.

Re:GCC and Clang handle statically known undefined behaviour by pif on Tuesday June 25, 2024 @10:38AM (#40789212)
> treating UB as something you'll see frequently in your career

Sure it is! I'm not talking about skills: everybody writes UB, at any time. I'm talking about attitude: when you see UB, you must strive to remove it, not to protect it!

Re:GCC and Clang handle statically known undefined behaviour by shadowgovt on Tuesday June 25, 2024 @12:53PM (#40790777)
If that is your position, it makes sense.

I didn't recognize it as your position because you presented "Developers must avoid UB in their code, at all costs" as supporting the preceding statement "This post has no point;" if your point is "developers should remove UB when they see it," then the point of this post is helping people see what UB looks like at the next layer of abstraction down as an aid to identifying and removing it.

(The C++ standard is over 2,000 pages. It's impractical to believe developers see UB by reading the C++ source code; most is identified by an application behaving incorrectly followed by inspection of the machine code to understand where the developer's assumptions about the C++ specification failed to match with the actual specification).

Re:GCC and Clang handle statically known undefined behaviour by pif on Tuesday June 25, 2024 @01:09PM (#40790978)
Just to be clear, I don't dislike this post for showing practical examples of UB. I'm just afraid that readers could take the wrong path and reason "This compiler does so-and-so, now I know how to better protect my current code", instead of the correct path of "Undefined means that I don't have the right to any expectation, thus I'll try and improve the portability of my algorithm".

Maybe I did not choose my words properly, I apologise.