DMD 0.174 release
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Wed Nov 15 11:50:23 PST 2006
Frits van Bommel wrote:
> Don Clugston wrote:
>> I spent four months of my spare time getting something like that to
>> work in C++ for all compilers. But this is D. With tuples it's easy,
>> you could even say trivial!
>>
>> R function(void *, U) makeCallable(R, U...)(R delegate(U) dg)
>> {
>> return cast(R function(void *, U))dg.funcptr;
>> }
>
> According to http://www.digitalmars.com/d/abi.html , 'this' is passed
> *last*, not first. So then we get:
>
> ----
> R function(U, void *) makeCallable(R, U...)(R delegate(U) dg)
> {
> return cast(R function(U, void *))dg.funcptr;
> }
> ----
>
> As far as I can see, that should work on the following conditions:
> * The input is not a variadic delegate.
> * The return value is not a struct. (Except that on Windows it should
> work for 1,2,4 or 8-byte structs, but not for other sizes)
>
> Haven't tested it though, I just thought something was off and checked
> the ABI ref.
I should add another disclaimer: This is based on the section "Function
Calling Conventions" of that page. I assumed the calling convention for
delegates is equal (with the context pointer replacing the 'this'
pointer), which I can't find explicitly mentioned on that page.
Though I think it's a logical assumption if you assume it was made as
easy as possible to produce delegates from member functions.
More information about the Digitalmars-d-announce
mailing list