Array as an argument, ambiguous behaviour.

Cooler kulkin at hotbox.ru
Wed Jan 29 06:48:11 PST 2014


> If, however, in fun3 you change the size of the array - it may 
> reallocate. Like, if you're appending to `x` - it will allocate 
> a new array and make x point to it. Now `a` and `x` point to 
> distinct arrays. And any change you do using `x` won't be seen 
> by `a`. And, yes, this is the intended behavior.

That exactly what am i asking for!
You have to know the body of fun3() to predict what happened with 
'a'.
When I call fun() there are 3 intentions:
1. I want just send the contents of 'a' to fun(). It can be done 
by a.dup, or you must sure that fun() has 'in' qualifier for it's 
argument.
2. I want fun() change content of 'a' array. This can be done by 
ensuring fun() has 'ref' qualifier for it's argument.
What intention should I have to call fun3()?


More information about the Digitalmars-d-learn mailing list