Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 24428

re: You can ask the compiler to answer your calling convention questions

$
0
0

@John Doe: I think we must distinguish between at least kinds of information sources here. In order of decreasing utility: (1) An authoritative spec that Microsoft (or whichever vendor we're talking about) is formally committed to implement; (2) direct observation of what the thing does in practice; (3) ad-hoc answers to concrete questions from people like Raymond.

I take your point to be that having (1) is superior to either of the two others. And I agree fully with that, having recently had the fun experience of extending an in-house compiler to generate code for the Windows Runtime API. Here there's essentially no answers of class (1) for the abstraction layers that lie between __stdcall and the fully projected "here's what to write" .NET or C++/CX syntax one finds in MSDN. And yes, that is infuriating.[*]

However, GIVEN a situation where (1) is not available, then Raymond's point here appears to be that (2) is superior to (3). That is also true, assuming that we're speaking about questions where (2) CAN logically provide complete answer, modulo some common sense. The concrete question in the posting is of that kind -- "is is this way or that way?". It's very hard to imagine that the answer would be "it depends" -- because what would it possibly depend on? Whether the size of the struct is a prime multiple of its alignment? Or whether there are more than 5 parameters EXCEPT the two invisible ones whose order we're asking about?

Sure, it would be even nicer if there were a complete self-contained description of the entire calling convention somewhere -- but then we're talking (1) versus (2), not (2) versus (3). There doesn't seem to be any advantage in waiting for someone at Microsoft to ask the compiler (because assuming that (1) simply doesn't exist even internally, that's what they'd do) over doing it oneself.

[*] It would be nice to have a neat conspiracy theory about how Microsoft is deliberately keeping this information secret as part of some convoluted plot to enslave the world, but it doesn't hold water because everything else indicates that they WANT people to create software using this technology and the absence of specs is simply due to resource constraints rather than actively malicious intent. Probably a lot of details were worked out by a bunch of guys around a whiteboard somewhere in Redmond and then they went each to their desks and implemented their end of the decisions, and nobody cared to write a self-contained description of the whole thing because there's a ship date looming and most of the sheeple app programmers just want source examples they can cut-and-paste from without understanding it anyway, and who other than us are ever going to care whether a class object for a runtime class without parameterless public constructors is required to implement IActivationFactory nevertheless?

[If you want to remove the variability over things like whether the size of the struct is a prime number (in practice: it can vary depending on whether the size of the struct is 8 or less), just run your test with the exact struct you want the answer for. The answer you get from the compiler is necessarily correct because that's how it would've happened if you had simply written a C program. -Raymond]

Viewing all articles
Browse latest Browse all 24428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>