Calling conventions

Bill Baxter dnewsgroup at billbaxter.com
Thu Dec 6 16:12:37 PST 2007


Mike wrote:
> On Thu, 06 Dec 2007 18:26:24 +0100, Bill Baxter 
> <dnewsgroup at billbaxter.com> wrote:
> 
>> I don't know much about calling conventions.  Are tehre really that 
>> many out in the wild?  If DMD doesn't support some of the ones that 
>> are in use, maybe the more reasonable thing would be to just add those.
> 
> Didn't you encounter that problem with bbTablet? Maybe the C++ compiler 
> you used knows that calling convention. If you decide to port bbTablet 
> do D, you'll be unpleasently surprised.

Bummer.  As might be expected, Microsoft's C/C++ compilers understand 
the calling convention (I think it comes from old windows 3.0 days).  So 
I didn't encounter any difficulties with the original version of 
bbTablet.  But if I ever get the chance I would definitely like to 
overhaul it for D (or actually give it a C API so that I can wrap it up 
for both D and Python use).  And that's why I asked you in my first 
message of this thread to describe what you had to do to call the wintab 
functions.  Still interested in knowing that, BTW.

On the other hand, if you've gotten something in D working, and are 
willing to share, I'd be happy to use that.  Are you going to make your 
tablet code available?

> I have no idea how many calling conventions there are - but since it's 
> pretty arbitrary how you pass the arguments I figure there are lots of 
> them, just few popular ones. A quick and certainly wrong Wikipedia 
> search gave me 15 for x86 only. A way to define the ABI (maybe name 
> mangling as well) would solve the problem once and for all. Put up a 
> project on dsource where ABI definitions are hosted and everybody can 
> submit anything they encounter in the wild. Any compiler, any weird 
> embedded processor, everything.
> 
> Maybe it'll be possible with macros, I don't know. Maybe something like
> 
> pragma(abi, "thiscall")
> {
>     void opCall(this, param1, param2)
>     {
>          // here be assembler code for any calls with a this pointer and 
> 2 parameters
>     }
> }
> 
> would be good.

I believe (but have no good evidence) that there are few enough actual 
calling conventions in use that it would be smarter in the long run to 
just make the compiler understand them all rather than creating a 
do-all, ultimately flexible, user-configurable system where 99.9% of all 
users will only use the built-ins anyway.


--bb



More information about the Digitalmars-d mailing list