Template

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Jun 6 08:02:04 PDT 2008


"Mael" <mael.primet at gmail.com> wrote in message 
news:g2biok$1epu$1 at digitalmars.com...
>> If you declare a two-dimensional (not sure about more dimensions..)
>> fixed-size array of fixed-size arrays, like "int[4][4]", it will be 
>> treated
>
> And what prevents the compiler to represent int[3][] arrays as 
> "single-dimensional" 3*length array, since this is what it would do
> in case the declaration was
> struct triple { int a, b, c ; }
> triple[] my_array ;

Ah, it seems that both are treated the same.  If you make such an array:

int[3][] a;
a.length = 5;

You'll find that the data for all the elements is contiguous, as with 
structs.  I wouldn't be surprised if the compiler would access the values in 
it using one pointer dereference instead of 2.

Fixed size arrays are weird, sometimes they're reference types and sometimes 
they're value types.  It's hard to remember when :S 




More information about the Digitalmars-d-learn mailing list