How initialize a static rectangular array (2-d matrix)

Justin Johansson no at spam.com
Thu Oct 8 18:58:51 PDT 2009


Jarrett Billingsley Wrote:

> On Thu, Oct 8, 2009 at 8:10 PM, Justin Johansson <no at spam.com> wrote:
> > I almost have to apologize for this question but ..
> >
> > How does one initialize a static rectangular array (2-d matrix) in D1?
> >
> > None of the following or other variations that I've tried compile with DMD 1.0.
> >
> > int[2, 3] matrix = [ 1, 2, 3,  4, 5, 6 ];
> 
> ..that's not how you declare a rectangular array type. It's int[3][2].
> 
> int[3][2] matrix = [[1, 2, 3], [4, 5, 6]];

Thanks Jarrett.

Am I having a blonde day?

   int[2,3] m = [ 1, 2, 3 ]; 
   writefln( "m=%s, .sizeof=%d", m, m.sizeof);

Compiles and prints:

m=[1,2,3], .sizeof=12

So what does that declaration, int[2,3], mean?

Think this is what threw me initially.

Thanks, Justin



More information about the Digitalmars-d-learn mailing list