Re: cast ref pointer

2018-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:26:54 UTC, Luís Marques wrote: The actual function bar also receives by ref its pointer. you might be better off receiving a pointer-to-pointer instead of ref. Then it will be encoded in the type and thus you can cast outer layers too and use intermediate mo

Re: cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:14:18 UTC, ag0aep6g wrote: On 01/18/2018 04:25 PM, Luís Marques wrote: You need a reinterpret-style cast here to get an lvalue: foo(* cast(int**) &ptr); Right, that's what I wanted. Ugh, for some reason I was totally confused about this :-)     w

Re: cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:20:35 UTC, Steven Schveighoffer wrote: 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 a

Re: cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:08:32 UTC, Adam D. Ruppe wrote: Simply define an intermediate. int* tmp = cast(int*) that_void_pointer; foo(tmp); In my actual case bar also receives its pointer by ref, so you would have to do something like: int* tmp = cast(int*) that_void_pointer; foo(t

Re: cast ref pointer

2018-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
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 thi

Re: cast ref pointer

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 04:25 PM, 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);     }     void main()     {     int i =

Re: cast ref pointer

2018-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 January 2018 at 15:25:38 UTC, Luís Marques wrote: 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. Simply define an intermediate. int* tmp = cast(int*) that_void_point

cast ref pointer

2018-01-18 Thread Luís Marques via Digitalmars-d-learn
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