On 13 March 2013 19:18, David Nadlinger <see@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';