Newbie initial comments on D language - delegate

Craig Black cblack at ara.com
Tue Jan 29 12:57:47 PST 2008


"Walter Bright" <newshound1 at digitalmars.com> wrote in message 
news:fnmrjo$109m$1 at digitalmars.com...
> Lionello Lunesu wrote:
>> Walter Bright wrote:
>>> To merge the two requires the generation of thunks at runtime to 
>>> manipulate the parameters and calling convention. It's doable, but not 
>>> simple.
>>
>> Perhaps allowing a delegate to point to a free function is enough to make 
>> people happy?
>>
>> It sure would please me ;)
>
> Me too, but it still changes the calling convention, and still needs a 
> thunk.

I don't understand why this is so difficult.  There already exists a 
function template that can be used to convert a function pointer to a 
delegate.  BCS showed it to me a while back.  Why not just have DMD call 
such a function to convert function pointers to delegates?

T delegate(A) Fn2Dg(T, A...)(T function(A) f)
{
  struct tmp { T ret(A args){ return (cast(T function(A))this)(args); } };
  return &(cast(tmp*)f).ret;
}

-Craig 





More information about the Digitalmars-d mailing list