Compilers Are Way Smarter Than I Thought
zacharyvoase.com
zacharyvoase.com
"He's honest, but you gotta watch him a little." - Tony (Chico Marx), "A Day at the Races" (1937)
Everyone talks about how close C is to assembly, and that's often true, but here we see how we benefit from how far it can be from assembly as well. The switch-to-jump-table trick is common enough some will claim it's obvious, but it isn't. Not unless you already know it, anyway; for a lot of newbies, the very idea of being able to jump to an address contained in a register is a non-obvious concept.
This is precisely the kind of trivial but non-obvious knowledge that should be encoded into compilers so the rest of us don't have to know it. That's a big reason why we have compilers in the first place.
Here's something that was on Hacker News a little while ago:
http://prog21.dadgum.com/166.html
http://news.ycombinator.com/item?id=5224576
"The Highest-Level Feature of C" is the switch statement