Casting delegates to void*
Iain Buclaw
ibuclaw at ubuntu.com
Wed Mar 13 13:24:32 PDT 2013
On 13 March 2013 19:18, David Nadlinger <see at klickverbot.at> wrote:
> Hi all,
>
> A quick quiz: Does the following function compile, and if yes,
> what will it return?
>
> ---
> void* delegateToPtr(void delegate() dg) {
> return cast(void*)dg;
> }
> ---
>
>
GDC's is also:
{
return <retval> = dg.object;
}
I think it would be better to be explicit in the case though.
eg:
---
// Returns context.
void* delegateToPtr(void delegate() dg) {
return cast(void*)dg.ptr;
}
// Returns function pointer.
void* delegateToPtr(void delegate() dg) {
return cast(void*)dg.funcptr;
}
---
So you aren't left guessing which one it could be.
Regards
--
Iain Buclaw
*(p < e ? p++ : p) = (c & 0x0f) + '0';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130313/9f0a3c96/attachment.html>
More information about the Digitalmars-d
mailing list