Multi-dimensional fixed arrays

DLearner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 30 14:02:37 PDT 2015


On Tuesday, 30 June 2015 at 20:33:31 UTC, jmh530 wrote:
> On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote:
>> [...]
>
> I think this is a good explanation.
>
> Looking through
> http://dlang.org/arrays.html
> I see that the multidimensional array indexing is not 
> particularly focused on (could be improved?). I tend to prefer 
> reasoning things through than relying on a rule (more likely to 
> forget the rule). Thus, I would recommend the OP looks at the 
> way they describe the prefix array declarations for 
> multidimensional arrays. They have the example
> int[4][3] b;  // array of 3 arrays of 4 ints each
> So you can think of b as an array containing 3 arrays with 4 
> ints each. For the OP's foo, he should think of foo as an array 
> containing 2 arrays with 1 int each. Moreover, it's more likely 
> that you want to index the arrays and then what's in the 
> arrays, i.e. it's more likely that you would want to do 
> something with the first array of foo and then the second array 
> of foo. This notation makes it a little bit easier to do that.

Out of curiosity, why can't D define a 2-dim array by something 
like:
int(2,1) foo;

which defines two elements referred to as:
foo(0,0) and foo(1,0)?

It just seems unnatural (if not actually dangerous) to me
to have the array index order reverse between definition and use.


More information about the Digitalmars-d-learn mailing list