D calling convention

Christian Kamm kamm-incasoftware at removethis.de
Tue Oct 28 09:28:58 PDT 2008


Tomas has done a lot of work on D ABI compatibility for LDC during the last
weeks. He's come quite far: except for the passing of some parameters in
EAX, things seem to work fine.

One point we couldn't understand though, is the reversal of parameters when
calling some D functions: Parameters are usually passed right-to-left,
except for nonvariadic D functions, where the order changes to
left-to-right. 

What is the reason for it?


If this was not so, and D functions would always pass parameters
right-to-left, it'd be very easy to call a member or nested function given
the type and address only: the context would just always go first in the
parameter list (and hence be passed last, possibly in EAX). As it is, you
have to put the context in as the last argument - except for variadics,
where it can go first again.

As a somewhat related, but separate issue, this would open the door to real
easy pointer-to-members. Given

class C {
  void foo(int i) { ... }
}

you could have

typeof(C.foo) == void function(C, int) 

and

auto memberfn = &C.foo;
memberfn(new C, 42);

would work too.




More information about the Digitalmars-d mailing list