www.digitalmars.com         C & C++   DMDScript  

D - Spec Clarification: Initializing arrays with arrays

reply Russ Lewis <russ deming-os.org> writes:
If we have this code:

int[] first;
int[] second = first;

Is second initialized by reference (that is, second points into the same
memory as first), or by value (a new copy is made)?
Sep 06 2001
parent reply "Walter" <walter digitalmars.com> writes:
By reference. To do a copy by value:

   second[] = first[];

Russ Lewis wrote in message <3B980434.DFCCE2A5 deming-os.org>...
If we have this code:

int[] first;
int[] second = first;

Is second initialized by reference (that is, second points into the same
memory as first), or by value (a new copy is made)?
Sep 06 2001
parent reply Russ Lewis <russ deming-os.org> writes:
Walter wrote:

 By reference. To do a copy by value:

    second[] = first[];
So int[] second = first; initializes by reference, while int[] second = first[]; initializes by value?
Sep 07 2001
parent "Walter" <walter digitalmars.com> writes:
Russ Lewis wrote in message <3B987832.7B8B6B19 deming-os.org>...
Walter wrote:

 By reference. To do a copy by value:

    second[] = first[];
So int[] second = first; initializes by reference, while int[] second = first[]; initializes by value?
Actually, there's no way to initialize a dynamic array by value.
Sep 07 2001