D's exact stack convention for D and C/C++

Adam Sansier via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 16 18:30:31 PDT 2016


I am trying to debug some really messed up code that makes no 
sense. It calls in some code that doesn't seem to be using the 
standard calling convention. The function definitions are exactly 
the same in both D and C++.

->func(param1, param2, param3, param4);

The call stack setup by C++ before the call is

001fa18d 002aff3c 00000014 000000c0 002b10f8 00c7fa34 001f16cc 
7f383000

The order is ret EIP, param1, param2, param3, param4, this

For D(naked asm)

00403ff3 002dc108 000000c0 00000014 002e73e8 026236f0 02ae4a78 
0019fe54

The order is ret EIP, param4, param3, param2, param1,

as one can see, the order is reversed. The functions are declared 
exactly the same in C++ and D(I just copied to D and marked 
extern(C++). It is part of a method(It is COM but that shouldn't 
matter?)).

Forget all that, What I'm really interested in is the exact 
calling conventions used in D and C and C++ and what they mean so 
I can make sure I know whats going on, cause something funky is 
happening and it's not on my end(I'm not messing with the order 
of this stuff directly).

So,

extern(C) = ?
extern(D) = ?
extern(C++) = ?
extern(Windows) = ?

C++ standard convention = ?
C standard convetion = ?
D standard convention = ?

Also, how is this pointer passed in method calls? ECX? Stack? If 
Stack, first or last? Does it change with calling convention?

I'm looking for only the facts, hopefully from the man himself.


More information about the Digitalmars-d mailing list