CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior..."

Channel:CppCon · Length:57:39 · Published:2016-10-06 · Views:93765

Watch on YouTube

Summary

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.

Why HN 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.

Chandler Carruth's talk on the subject was really useful for my own understanding of the reasoning behind UB — HN, 2018

C, C++, Rust, Go & systems languages · Software performance & optimization · Compilers, interpreters & program analysis

Subtitles (excerpt)

All right, so we're going to talk about undefined behavior. Uh, my name is Chandler Ruth. I work at Google. I work on C++ for Google. I work on clang and LVM, the compilers. And one thing that I've done recently is I've I've, you know, started to try and and talk with people about undefined behavior. Um, so how many folks here are a little bit afraid of undefined behavior in their source code? Everybody. How many folks here think that this font is too small when it comes to talking about undefined behavior and how scared they are? Is that is that getting closer? That was too small. All right. Still too small. I mean, there there's a lot of there are a lot of issues here, right? People are actually really kind of afraid of this. Um, and and I think it's something that, you know, we as a community need to try and deal with better. Uh, so so that's what this talk is is about. This talk is not going to try and justify all forms of undefined behavior. It's not going to try and, you know, remove all undefined behavior. The the primary goal of this talk is to help us actually think about undefined behavior in a more productive way. Now, the number one thing I dislike about undefined behavior is this obsession with

On Hacker News

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… — moefh, 2023-08
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… — Joky, 2018-11
Chandler Carruth's talk on the subject was really useful for my own understanding of the reasoning behind UB: [VIDEO] — lyricaljoke, 2018-05
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 [VIDEO] — kllrnohj, 2018-03
ISO C99 actually defines multiple types of deviating behaviour. What you're describing is closer to implementation-defined behaviour than anything else. The three behaviours relevant in this discussion, from section 3.4: 3.4.1 implementation-defined behavior unspecified behavior where each implementation documents how the choice is made EXAMPLE An example of implementation-defined behavior is the… — atiedebee, 2026-02

Related videos