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.

How C++ Resolves a Function Call

299 pointsby goranmoominabout 4 years ago

15 comments

WalterBrightabout 4 years ago
I was able to use my experience implementing C++ name lookup rules to make a less complex one for D:<p>There&#x27;s no notion of a &quot;primary&quot; template. Templates are looked up like functions are.<p>C++ has rather complex function overloading rules that differ substantially from template overloading rules. The former is a hierarchical list of rules, the latter is based on partial ordering. D uses partial ordering for both.<p>D doesn&#x27;t need argument dependent lookup, because it has modules.<p>D lookup sees all the declarations in a module at once, not just ones prior to the point of use.<p>The end result works pretty much the same, and hardly anyone notices the difference. Except for that last point - in C and C++, the order of declarations is inverted. The private functions come first, the public ones last, because lookup is dependent on the lexical order. D code is written with the public ones first, private ones last.
评论 #26476528 未加载
评论 #26474244 未加载
评论 #26474441 未加载
mkoubaaabout 4 years ago
I usually try to get away with reading as little of the manual as possible until I absolutely have to. Articles like this really help cavemen like me because this is leaps and bounds better than reading the actual c++ standard!
评论 #26472988 未加载
评论 #26474251 未加载
kazinatorabout 4 years ago
C++ resolves certain kinds of tricky function calls via a remote procedure call that sends an SMTP mail to the ISO committee, and waits for a reply. (It&#x27;s compile time though, no biggie.)
评论 #26477528 未加载
tlbabout 4 years ago
It&#x27;s curious how the C++ standard is written with a bunch of rules, rather than an algorithm. The algorithmic version in the article is much clearer to programmers. You&#x27;d think the C++ standards committee would write the standard for programmers instead of for -- I don&#x27;t even know who it&#x27;s for. Bureaucrats? Tax lawyers? SF Zoning regulation enforcers?
评论 #26472977 未加载
评论 #26472967 未加载
评论 #26472803 未加载
评论 #26472712 未加载
评论 #26472776 未加载
评论 #26472683 未加载
qalmakkaabout 4 years ago
What has always fascinated me of C++ is how incredibly complex, yet wild, it is. You can do basically everything, you can create horrible monsters and discover beautiful patterns backed by strong type safety. It might not be for everyone, but yet I find it can be as rewarding as it is frustrating. You always learn something, and you can always dig yourself out of any hole, it just requires effort and skill.
aruncabout 4 years ago
Unrelated to C++, but the diagrams (svg) looks nice. Are these created from text format or via some diagram tool, because if it is from text, it&#x27;s nice to use in architecture diagram (asciidoc&#x2F;markdown), etc and version control with git.<p>PlantUML works well for sequence diagrams, but for the rest, the output is not pleasing to look at.
评论 #26476742 未加载
arcticbullabout 4 years ago
If skynet ever happens, it&#x27;ll be a self-aware C++ compiler, mark my words. That&#x27;s why it hated us so much in the Terminator documentaries.
评论 #26474497 未加载
评论 #26476262 未加载
评论 #26474265 未加载
ktpsnsabout 4 years ago
Wow, this website is one of the first ones in the wild I see which seamlessly integrate SVG into the text flow to produce a single look. Amazing work!
CyberRabbiabout 4 years ago
Advanced function resolution technology is one of the main reasons I use C++. The combination of being statically typed yet allowing users to create elaborate function dispatch hierarchies is unmatched.
评论 #26473538 未加载
评论 #26473338 未加载
einpoklumabout 4 years ago
Rule of thumb: If your code has ambiguities that make you reach for the details of name resolution rules, or depend on some finer point within them, then - seriously consider differentiating the names.<p>In the example in the article - I would go to some trouble to avoid having both:<p><pre><code> namespace galaxy { void blast(Asteroid* ast, float force); } </code></pre> and<p>template &lt;typename T&gt; void blast(T* obj, float force);<p>either blasting asteroids happens in the context of galaxies, or it doesn&#x27;t. If there are _different kinds_ of blasting of asteroids - very well, make that explicit.<p>Also,<p>bool blast(Target target);<p>would be somewhat confusing, since people may expect `blast()` to not return anything and will neglect to check the returned value. And wouldn&#x27;t it make more sense to just have a default amount of force for the blast? ... again, if it&#x27;s a different kind of blast, don&#x27;t name both functions the same.<p>PS:<p>* &quot;Better is a good name than fine oil&quot; (that&#x27;s a biblical proverb). * Don&#x27;t be a smart-ass when naming! You&#x27;ll smile for a second, others will cry for years. * Don&#x27;t be stingy with a few more characters in your name - we can handle it.
wyldfireabout 4 years ago
&gt; , it should at least be possible to implicitly convert each argument to its corresponding parameter type.<p>Oh no! You just got burned (maybe). Make sure you turn on your compiler&#x27;s warnings to find bogus-but-legal implicit conversions.
rjzzleepabout 4 years ago
This is a good article in terms of context, but I found it much easier to understand how C++ does class functions when I first saw this in a disassembly output. I guess I&#x27;m a more visual learner that has a fairly hard time following a lot of text.
评论 #26474507 未加载
mshockwaveabout 4 years ago
We need more articles like this on other aspects of C++
评论 #26474302 未加载
rapsacnzabout 4 years ago
And this is one of the reasons why C++ is a mess.
unnouinceputabout 4 years ago
Or use a good IDE which would have something like &quot;right click -&gt; jump to declaration&quot; and it will show you what&#x2F;where the function is implemented. Or at least that&#x27;s what I do to keep up my productivity instead of wondering at the marvels of overloading &#x2F; namespaces that export same function names.
评论 #26474009 未加载
评论 #26474674 未加载
评论 #26474006 未加载