Wow, my head is spinning! It may very well be that second glass of wine, but I think it’s largely the fault of Joseph M. Newcomer’s outstanding article/blog post Mythology in C++: Exceptions are Expensive.
Newcomer starts out with some flattering words about the PDP-11 minicomputer where the C language matured into the language many of us learned in school (at least the K&R version of it). But after a couple paragraphs of pleasantries, the reader is caught in a whirlwind of facts, figures, and quite convincing arguments that perhaps some truisms programmers are taught don’t apply to modern CPU architectures.
For example, Newcomer points out the popular for(;;) idiom for infinite loops in C is preferred over while(true) because the original PDP-11 C compiler generated inefficient code for the latter. But modern compilers, and even later compilers for the PDP-11 knew how to to make the while version more efficient than the for one.
As the title implies, the bulk of the article deals with exception handling in C++, the most famous object-oriented offshoot of the original C language. For years, we’ve heard about how expensive exception handling is, while chip designers and operating system designers worked to make sure exceptions only had a tangible effect when they actually occur.
I’ll admit, tonight’s cabernet got in the way of me absorbing all the explanations. But I did walk away with the sense that Newcomer has only peeled away one layer of the onion here, and we’re going to start seeing more revelations like this, hopefully backed by the same extensive research and testing.

On a personal note, this reminds me of one C++ class I took in college. The teacher had just finished explaining object properties, and I raised my hand to ask what the syntax was for specifying the width of each property in bits (bit fields). You can do this with structs in C, and I loved using this feature to cram two small values in one 8-bit byte, but my teacher was puzzled as to why anyone would need to do that. I started researching why this was left out of C++ and came away with a deeper understanding of how having megabytes of RAM available made computers perform faster (they don’t have to deal with hacky bit field optimizations like that, among other things) and how modern compilers optimize for alignment.
There’s a good chance the compiler was laughing at my “optimizations” and ignoring them.