Array as an argument, ambiguous behaviour.
Ali Çehreli
acehreli at yahoo.com
Wed Jan 29 06:35:01 PST 2014
On 01/29/2014 02:55 AM, Cooler wrote:
> Consider 3 functions taking array as an argument:
>
> void fun1(in int[] x){...}
> void fun2(ref int[] x){...}
> void fun3( int[] x){...}
>
> auto a = new int[10];
>
> fun1(a); // Guaranteed that "a" will not be changed
> fun2(a); // Guaranteed that we will see any change to "a", made in fun2()
> fun3(a); // Changes to "a" in fun3() may be or may be not visible to the
> caller
>
> In case of fun3() we have ambiguous behaviour, depending on the body of
> the function.
>
> Am I right?
> Is that intentional?
Yes, that is how slices work in D. The following article explains the
"non-determinism" that you mention:
http://dlang.org/d-array-article.html
Ali
More information about the Digitalmars-d-learn
mailing list