Before it's too late: delegate calling convention

Lionello Lunesu lio at lunesu.remove.com
Wed Nov 1 22:22:52 PST 2006


Gregor Richards wrote:
> Jarrett Billingsley wrote:
>> "Gregor Richards" <Richards at codu.org> wrote in message 
>> news:4548CD75.80803 at codu.org...
>>
>>
>>> And a solution that's less nasty: Allow casting of function pointers 
>>> to delegate pointers by automatic thunktion generation.
>>
>>
>> I like that a lot better.  But if you're wrapping a function pointer 
>> in a delegate reference, is a thunk really needed?  I mean, the 
>> function won't be accessing the context pointer, so why not just set 
>> the delegate's context pointer to null?
>>
>> i.e.
>>
>> int foo()
>> {
>>
>> }
>>
>> int delegate() bar = cast(int delegate())&foo;
>> // bar's function address is &foo, and bar.ptr == null
>>
> 
> The context pointer isn't magic, it's passed as an argument to the 
> function. So if you directly casted, you'd end up with an extra argument 
> passed to the function, any argument processing would be off-by-one.
> 
>  - Gregor Richards

Actually, it's passed in a register, so it could be made to work.

L.



More information about the Digitalmars-d mailing list