CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior..."
Why Hacker News recommends it
HN points to it whenever undefined behavior comes up, as the best explanation of the reasoning behind UB, though some dispute its framing.
Recommended by 4 people across 4 different months, 2016 to 2026.
What it is
Chandler Carruth's CppCon 2016 talk tries to defuse the heated debate over undefined behavior in C and C++. He explains from the compiler writer's perspective why UB exists and how it enables optimization.
What people said
Recommends kllrnohj · 2018-03 · Hacker News · on “A Usable C++ Dialect That Is Safe Against Memory Corruption”
The generally recommended thing for catching & fixing this is: [LINK] CppCon has also had a lot of great talks on UB and why it is what it is, such as [this video]
Recommends lyricaljoke · 2018-05 · Hacker News · on “Depressing and faintly terrifying days for the C standard [pdf]”
Chandler Carruth's talk on the subject was really useful for my own understanding of the reasoning behind UB: [this video]
Recommends Joky · 2018-11 · Hacker News · on “Trip report: Fall ISO C++ standards meeting”
Actually I discourage my colleague to use unsigned especially because they can overflow. The problem with overflow is that most of the time it is a program bug if there is an overflow that wasn't intended. Using signed arithmetic means that you can actually trap on overflow and catch these bugs (using fuzzing for instance). Chandler explained it nicely in his CPPCon 2016 talk "Garbage In, Garbage Out: Arguing about Undefined Behavior...". I encourage to watch the full talk but here is one relevant example: [this video] And here he mentions how Google experimented with this internally: [this video]
Recommends moefh · 2023-08 · Hacker News · on “A Guide to Undefined Behavior in C and C++”
One man's "broken code produced by the compiler" is another man's "excellently optimized code by the compiler". Where to draw the line is not always clear, but here's a very clear-cut example[1] where emitting a warning would be bad. If you don't want to watch the video, it's basically this: - the code technically contains undefined behavior, but it will never be actually triggered by the program - changing the code to remove undefined behavior forces the compiler to emit terrible code Making the compiler yell at the programmer in this case would be terrible, but it's clearly a consequence of what you're asking. [1] [this video]
Cites pjmlp · 2016-10 · Hacker News · on “Alpine Edge has switched to libressl”
I very much doubt it, as it goes against the C culture of micro-optimize each code line as it is written, without any feedback from a profiler because "the coder knows best!". Since I know C (1992), I have seen quite a few times people write code to go fast as they can and apply compiler optimization tricks for use cases where it hardly matters. Also many of the issues regarding UB go back to the early ANSI C days, when it was the wild west of C dialects outside UNIX and no vendor wanted to give up on their own extensions. As for C and C++ compiler writers view on UB: [this video]
Cites tynorf · 2020-01 · Hacker News · on “Let's Destroy C”
I haven't actually watched it in a while, but are you referencing this talk by Chandler Carruth? [this video]
Cites monsecchris · 2022-01 · Hacker News · on “Almost Always Unsigned”
Signed integer overflow causing undefined behaviour allows the compiler to make significantly better optimisations. Here is Chandler Carruth, and clang developer, talking about it: [this video]
Cites xscott · 2022-05 · Hacker News · on “How I think about C99 strict aliasing rules”
It's not obvious unless you read and think about the assembly, but bonzini's point was that using a 32 bit signed int (which is not allowed to overflow) means the compiler can cleverly promote it to use register RAX as an index without any other shenanigans to deal with 32 bit overflow. RAX is a 64 bit register for integers or pointers. There are reasons why this might be advantageous over using EAX, which is the name for the low 32 bits of RAX. It's very possible that bonzini is referring to the example in the following link: [this video] Back to your overall point though, you're right that there's frequently an advantage to having your bulk data use smaller data types. It's better for caching a
Cites obi1kenobi · 2022-11 · Hacker News · on “Falsehoods programmers believe about undefined behavior”
Suggestions like this are unfortunately quite infeasible (they fall under the hat of "define all the behaviors"), and the talk I linked in the post goes into why: [this video] (I'm the post's author.)
Cites xscott · 2023-06 · Hacker News · on “Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022”
I know you're just trashing C UB because that's fashionable, but if you really think about it there are two popular options, and you can't have both at the same time: a) UB enables valuable optimizations and is important to keep (or even add) when performance matters b) UB makes the language unusable/insecure to anyone but genius level experts and should be avoided Whenever someone (including famous/relevant people like Dennis Ritchie [0], DJ Bernstein [1], or Linus Torvalds [2]) tries to suggest cleaning up, removing, or simply not adding new cases of undefined behavior in C/C++, the optimization experts come running from the other room screaming about how important it is that "signed integ