Before it's too late: delegate calling convention

Gregor Richards Richards at codu.org
Wed Nov 1 08:38:13 PST 2006


Gregor Richards wrote:
> Lionello Lunesu wrote:
> 
>> Just thought I'd post this before it's too late (some will argue it 
>> already is too late, but I don't think so):
>>
>> Please make the calling convention for delegates compatible with the 
>> one for functions. I want to be able to write my API using only 
>> delegates, and allow users to pass also globals (function pointers) 
>> for callbacks.
>>
>> The two workarounds currently are
>>
>> * wrapping the function in a dummy delegate literal (I don't like 
>> having to do this; it's not about the work, but it looks clumsy)
>>
>> * provide an API using delegates and one using function pointers (much 
>> like std.thread.Thread's constructor; needs extra code, for what?)
>>
>> If I'd be asked to submit ONE issue for "to do before 1.0", this would 
>> be it.
>>
>> L.
> 
> 
> One major problem: This would make function pointers incompatible with C 
> function pointers, making interfacing with a huge chunk of software 
> impossible.
> 
> One solution nobody will like (hell, I don't even like it): Have a 
> special value for the scope part of the delegate that basically implies 
> "this is not really a delegate", and will cause the call to the delegate 
> to not pass it as the first argument. This would incur an if for 
> delegate calls, but would make function pointers castable to delegates.
> 
>  - Gregor Richards

And a solution that's less nasty: Allow casting of function pointers to 
delegate pointers by automatic thunktion generation.

  - Gregor Richards



More information about the Digitalmars-d mailing list