Multi-dimensional fixed arrays

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 30 13:17:12 PDT 2015


On Tue, 30 Jun 2015 20:09:50 +0000, DLearner wrote:

> Suppose:
> 'int [1][2] foo;'
> 
> Probably I misunderstand, but TDPL seems to say that foo has two
> elements:
> foo[0][0] and foo[1][0]
> 
> as opposed to two elements:
> foo[0][0] and foo[0][1]
> 
> Is this correct?

No.  The order of braces when indexing is the opposite of the order when 
declaring.
The declaration
> int [1][2] foo;
reads innermost to outermost, "((int [1] ) [2])"

When indexing foo, you index from outermost to innermost, so
> foo[1]
means the second one-element array and
> foo[1][0]
means the first element of the second one-element array.


More information about the Digitalmars-d-learn mailing list