This works, obviously (i.e. it prints 42):

    void foo(ref int* a)
    {
        static int j = 42;
        a = &j;
    }

    void bar(int* ptr)
    {
        foo(ptr);
        writeln(*ptr);
    }

    void main()
    {
        int i = 7;
        bar(&i);
    }

Unfortunately, if bar for some reason receives a void* pointer (e.g. C callback) this doesn't work:

    void bar(void* ptr)
    {
        foo(cast(int*) ptr); // error
        writeln(*cast(int*) *ptr);
    }

I think the underlying idea is sound (use ptr as an lvalue, but with int* type), but since you can't cast(ref int*), I don't know how to express it in D code.

Reply via email to