Is this documented behaviour?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 23 10:11:42 PDT 2013
On Tuesday, July 23, 2013 18:34:51 John Colvin wrote:
> void foo(ref int a)
> {
> a = 5;
> }
>
> void main()
> {
> int a = 0;
> int* aptr = &a;
>
> foo(*aptr);
> assert(a == 5);
>
> a = 0;
>
> int b = *aptr;
> foo(b);
> assert(b == 5);
> assert(a == 0);
> }
>
> The fact that adding an explicit temporary changes the semantics
> seems weird to me.
There is no such thing as an "explicit temporary." You declared a new
variable, and since int is a value type, of course any changes to that new
variable had no effect on the int that was used to initialize it. And you can't
use temporaries with ref parameters regardless.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list