Multi-dimensional fixed arrays

DLearner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 1 08:49:55 PDT 2015


On Tuesday, 30 June 2015 at 22:04:24 UTC, Justin Whear wrote:
>>>
> alias IntList = int[10];
> IntList[3] myIntLists;
> int[10][3] myOtherIntLists; // same type as above
<<<
I understand the rationale, but some issues:

1.  The rationale implicitly takes treats an n-dim array as a 
(n-1)-dim array x (1)-dim array.

Are we sure this is correct: FWIW, I think an n-dim array is just 
a set of n-tuple indexes each mapping 1-1 to array elements.
And no more structure than that.

So, although the order of the indexes is important (otherwise we 
find the wrong element), no subset of tuples (perhaps generated 
by holding one or more indexes constant) is more important than 
any other.

2. I _thought_  it was design goal of D that a valid C program, 
if it compiles under D at all, produces the same output.

That cannot be true if array index order altered.

3. Obscurity: Someone faced with the array definition 'int[a][b] 
foo;'
is going to instinctively think that the instruction 'bar = 
foo[x][y];'
means that, potentially, 0 <= x < a and 0<= y < b.
(Which is why if the current design is fixed, I suggested using 
() instead of [] as an alternate which does match access order to 
definition order)

Though, in the case of 3., (and really a different question),
there is case for a compiler option making valid range 1 <= x <= 
a and 1<= y <= b,
as off-by-one error is commonplace bug in C.


More information about the Digitalmars-d-learn mailing list