Before it's too late: delegate calling convention
Gregor Richards
Richards at codu.org
Wed Nov 1 14:45:51 PST 2006
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
More information about the Digitalmars-d
mailing list