Passing dynamic arrays

Jens Mueller jens.k.mueller at gmx.de
Mon Nov 8 14:11:47 PST 2010


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


More information about the Digitalmars-d mailing list