Array as an argument, ambiguous behaviour.

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Thu Jan 30 13:20:31 PST 2014


On Wednesday, 29 January 2014 at 10:55:57 UTC, 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?

I believe what you are asking for is "head const." D does not do 
this, search for "head const dlang" and you'll probably find some 
discussion in it.


More information about the Digitalmars-d-learn mailing list