Differing semantics between multidimensional fixed-length array and slice initialization

Nicholas Smith nmsmith65 at gmail.com
Sun Mar 31 18:36:48 PDT 2013


Hello there,

So I noticed something about the semantics of multidimensional 
fixed-length array vs slice initialization:

Code:

int[2][3] array;
writeln(array.length, " ", array[0].length);
int[][] slice = new int[][](2, 3);
writeln(slice.length, " ", slice[0].length);

Output:

3 2
2 3

So it seems that int[2][3] means "an array of 3 int arrays of 
length 2", while new int[][](2, 3) means "an array of 2 int 
arrays of length 3".

This seems like a direct conflict of semantics, and I was 
wondering whether this was an intentional design choice, or an 
oversight. Can anyone explain reasoning behind this?


More information about the Digitalmars-d-learn mailing list