Value vs. reference semantics, and pointers

Don Clugston dac at nospam.com.au
Thu Mar 23 00:59:20 PST 2006


S. Chancellor wrote:
> On 2006-03-21 00:14:15 -0800, Scott L. Burson 
> <Scott_member at pathlink.com> said:
> 
>> Hi,
>>
>> As a newcomer to D I want to say first that it looks like a very clean 
>> and
>> well-thought-out design, free of the endless frustrations of C++.  As 
>> a Lisp
>> fanatic, I am particularly glad to see that you have included local 
>> functions,
>> function literals, and closures, though the distinction between function
>> "pointers" and delegates strikes me as superfluous ... oh, I see you 
>> are already
>> considering eliminating
> 
> Delegates and function pointers are fundamentally different structures 
> in memory.  In order to maintain compatibility with C binaries there 
> must be a distinction made between the two.  C can't handle delegates.

Not necessarily. Currently a delegate is
struct {
Object * the_this;
function the_function;
}

and an invocation is:

mov ebx, deleg.the_this;
call deleg.the_function;


At creation of the delegate, you can create a thunk in memory, 
consisting of the lines

the_thunk:
mov ebx, the_this;
jmp the_function

and then the delegate is just a function pointer.
Invocation is

call the_thunk

just like an ordinary function pointer. That way, you can pass it to C 
and everything will work fine. (FWIW, this is exactly how ATL works, the 
thunk is created on the stack (!) ).

AFAIK this will happen for D 2.0.





More information about the Digitalmars-d mailing list