refInt = ref int: how to achieve this? or is this a bug?

Paul Backus snarwin at gmail.com
Thu Jun 18 00:20:10 UTC 2020


On Wednesday, 17 June 2020 at 23:58:37 UTC, mw wrote:
>
> It has to be done: because the C lib only accept void* as value.
>
> So on the D side, need to pass to C:
>
> -- primitive types, class (essentially pointers) by value
> -- struct, union, array|string, by reference
>
> The discussion here is how to make this passing code simple to 
> write.

void* address(T)(ref T arg)
{
     static if (is(T == class) || is(T == interface))
         return cast(void*) arg;
     else
         return cast(void*) &arg;
}


More information about the Digitalmars-d mailing list