Simple array init question

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Apr 9 18:00:07 PDT 2007


"Dan" <murpsoft at hotmail.com> wrote in message 
news:evem9b$a9p$1 at digitalmars.com...
>
> Fascinating.  I thought static arrays were implemented in the same way (in 
> terms of structure) as dynamic arrays.  I'm curious then if I declare a:
>
> struct z { int[] y; }
>
> static z[] x = [ { y:[1,2,3] } ];
>
> Does this implement a static array, or a dynamic array?  I *hope* a 
> dynamic one, as otherwise I will have to rewrite my entire Global_init 
> routine for Walnut 2.x.  : o

Dynamic arrays.  Nothing in the brackets -- always dynamic.

> According to the D spec, that should compile as a rectangular array.  I 
> haven't tried it.  I have read the spec.
>
> See:
> http://digitalmars.com/d/arrays.html
> and visit "Rectangular Arrays".

quote:
================
Fortunately, D static arrays, while using the same syntax, are implemented 
as a fixed rectangular layout:
double[3][3] matrix;

declares a rectangular matrix with 3 rows and 3 columns, all contiguously in 
memory. ***In other languages***, this would be called a multidimensional 
array and be declared as:
double matrix[3,3];
================

Notice the "in other languages" bit ;)  (though I have no idea _what_ other 
languages Walter's referring to in this sentence..)

> PS: Walter, any chance we can get <a name=""> so we can link directly to 
> specific parts of the spec?
>

I think there are some anchors, they're just not visible outside the page 
source.  That would be very convenient, of course. 





More information about the Digitalmars-d mailing list