cast ref pointer

Steven Schveighoffer schveiguy at yahoo.com
Thu Jan 18 16:20:35 UTC 2018


On 1/18/18 10:25 AM, Luís Marques wrote:
> 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);
>      }

Note, this, to me, seems odd. Of course this is not the full case, but 
you are not affecting anything except for the value of the local `ptr`. 
So I would be concerned this may not be what you want (if you are 
looking to affect something outside the callback).

Other than that, the other responders are right, you just need to 
reinterpret the pointer.

-Steve


More information about the Digitalmars-d-learn mailing list