Monday, September 11, 2023

C and C++ compilers and undefined behavior

The first article goes into how it's increasingly difficult to avoid triggering undefined behavior unless you're very careful, and how compilers are emitting "optimzed" code that has little to do with the original because it's undefined.

Lumping both non-portable and buggy code into the same category was a mistake. As time has gone on, the way compilers treat undefined behavior has led to more and more unexpectedly broken programs, to the point where it is becoming difficult to tell whether any program will compile to the meaning in the original source. This post looks at a few examples and then tries to make some general observations. In particular, today’s C and C++ prioritize performance to the clear detriment of correctness.


The second article mkaes a lot of the same points, but perhaps in more depth, going through some real world examples of serious bugs that came out of small programming errors.