Function to delegate conversion
BCS
BCS at pathlink.com
Mon Jun 26 14:17:01 PDT 2006
Kirk McDonald wrote:
>
> The following dirty, dirty hack /appears/ to work, at least in this
> trivial case:
>
> import std.stdio;
>
> struct DG {
> Object instance;
> void function() fn;
> }
>
> union U {
> DG fake_dg;
- void delegate() real_dg;
+ void* real_dg;
> }
>
> class A {
> void foo() { writefln("A.foo()"); }
> }
>
> void main() {
> A a = new A;
> void function() fn = &A.foo;
>
> U u;
> u.fake_dg.instance = a;
- u.fake_dg.fn = fn;
+ u.fake_dg.fn = cast(void*)fn;
>
> // Call it
> u.real_dg();
> }
>
That should also work and won't care about types. But it is still
really, really dirty. But it's more portable that the last solution I
saw, That one used ASM hacking.
More information about the Digitalmars-d
mailing list