D calling convention

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Oct 28 10:17:42 PDT 2008


On Tue, Oct 28, 2008 at 12:28 PM, Christian Kamm
<kamm-incasoftware at removethis.de> wrote:
> 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.
>
>

All of these things would make me happy.  :)



More information about the Digitalmars-d mailing list