www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Passing dynamic arrays

reply Kagamin <spam here.lot> writes:
Jens Mueller Wrote:

 I find this behavior rather strange. Arrays are neither passed by value
 (copying the whole array) nor by reference. I see reasons for doing it
 like this, e.g. doing array = array[1..$] inside should not affect the
 outside.
 But I wonder whether these semantics are well enough documented?

It may take some effort to explain it. Does it help, if you think about T[] as not an array but a slice?
Nov 08 2010
parent Jens Mueller <jens.k.mueller gmx.de> writes:
Kagamin wrote:
 Jens Mueller Wrote:
 
 I find this behavior rather strange. Arrays are neither passed by value
 (copying the whole array) nor by reference. I see reasons for doing it
 like this, e.g. doing array = array[1..$] inside should not affect the
 outside.
 But I wonder whether these semantics are well enough documented?

It may take some effort to explain it. Does it help, if you think about T[] as not an array but a slice?

Yes. This behavior is well explained when one thinks about passing a slice of data instead of an dynamic array. With a dynamic array I think about the std::vector. But passing a reference to a std::vector is not the same as passing a slice. Jens
Nov 08 2010