Jonathan Blow on Why C++ Undefined Behavior Is a Mistake

Jonathan Blow Clips · 5 825 vues · 68 👍 · 04/12/2026

Check out my Plarza: https://jonathanblowclips.plarza.com
In an April 5, 2019 compiler programming stream, Jonathan Blow pauses from implementing atomic intrinsics to answer chat about a conference talk by Chandler Carruth defending undefined behavior in C and C++. He says the talk's examples, shifting into the sign bit and signed integer overflow, are old problems a language designer could solve in ten minutes of thought, and that C was designed around platform-defined behavior: programmers in the 1970s and 80s knew their numbers were two's complement and knew exactly what their code did in edge cases like zero. Asked whether undefined behavior helps the optimizer reason about loops with signed indices, he argues a language should instead let programmers declare facts such as 'this is never negative', which gives the compiler the same information, documents the code and allows checks that help debugging, instead of surprising the programmer. He states that his own language has zero undefined behavior. He wonders whether people pushing undefined behavior are being dishonest or genuinely do not understand how C was used, describes failing to explain platform-defined behavior to a visiting Sony compiler team working on a fixed hardware platform, and argues that C++ changed 'the result is not defined' from meaning defined by the platform to meaning illegal, a philosophical change that makes it harder to work with the hardware. He agrees that C should have said implementation-defined throughout. He notes that Carruth's other talks he has seen are good.

Chapters
0:00 A talk defending undefined behavior
0:16 Old examples with easy fixes
3:24 Does UB help the optimizer?
4:53 Zero UB in his language
5:31 Dishonesty or incompetence?
6:18 Fixed platforms have no UB
7:23 How C++ changed 'not defined'
8:41 Implementation-defined behavior

Clip from Jonathan Blow
Original: https://youtube.com/watch?v=hjvtzriNlMU&t=11160s
Twitch: https://twitch.tv/j_blow
YouTube: https://www.youtube.com/@jblow888

#jonathanblow #programming #gamedev #jai #softwareengineering


Source: Jonathan Blow stream: Compiler Programming, Polymorphic Intrinsics https://youtube.com/watch?v=hjvtzriNlMU&t=11160s
Streamed: 2019-04-05

#C programming #C++ #Chandler Carruth #Jai #Jonathan Blow #compiler optimization #implementation-defined behavior #programming #programming language design #systems programming #two's complement #undefined behavior