TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Compilers Are Way Smarter Than I Thought

5 pointsby zacharyvoaseabout 12 years ago

2 comments

mooism2about 12 years ago
C compilers have been optimising switch statements like this since <i>at least</i> the 90s, haven't they?
评论 #5313539 未加载
derlethabout 12 years ago
If you think that's cool, someone will be around shortly to explain how gcc will use SSE opcodes to improve the speed of string handling functions.<p>"He's honest, but you gotta watch him a little." - Tony (Chico Marx), "A Day at the Races" (1937)<p>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.<p>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.<p>Here's something that was on Hacker News a little while ago:<p><a href="http://prog21.dadgum.com/166.html" rel="nofollow">http://prog21.dadgum.com/166.html</a><p><a href="http://news.ycombinator.com/item?id=5224576" rel="nofollow">http://news.ycombinator.com/item?id=5224576</a><p>"The Highest-Level Feature of C" is the switch statement