“Which Machine Am I Coding To?”
summary
Explains that C++ targets a formal C++ abstract machine not real hardware, documents the as-if rule that lets compilers remove dead computation (example: three loop forms optimized away at -O2), and details nondeterminism like unspecified evaluation order, implementation-defined sizes (char bits may not be eight), and pointer comparison rules. Demonstrates a concrete bug: two threads ++ on a plain int sometimes yields fast but wrong results versus slower atomic int; cites Matt Godbolt and Fred’s benchmarks; calls out undefined behavior and observable behavior.
AI-written summary · about
chapters (15)
- 0:00Intro
- 1:50The Abstract...
- 7:52C's abstract machine?
- 9:12C++'s abstract machine?
- 17:27Implementation-defined
- 18:59Unspecified elements
- 20:19Undefined elements
- 22:15Program execution
- 24:35The role of main()
- 25:36Memory model (short overview)
- 30:27Abstract vs concrete machines
- 34:07Impact on programming
- 38:59Impact on language design
- 41:04Tools you should know and use
- 41:39References
related talks
46m“My Little Optimizer: Undefined Behavior is Magic"
58mWhat is C++
44mImplementing Software Machines in Go and C
01h 11mProgramming language memory models: Problems, solutions, and directions
07mISO/IEC 14882
22mCompilers should get over themselves and respect semantic dependencies!
01h 00mType punning in modern C++
58mGarbage In, Garbage Out: Arguing about Undefined Behavior...
