Edit: And perhaps some special treatment by the compiler for optimization. I find multi-d arrays counter-intuitive and clumsy on some situations. Also, currently I'm forced to write ugly code like array[x,y][i].
Edit: And perhaps some special treatment by the compiler for optimization. I find multi-d arrays counter-intuitive and clumsy on some situations. Also, currently I'm forced to write ugly code like array[x,y][i].
If you have this code:
int a[10][10];
then: &a[x][y] == ((char *)a + x * sizeof(a[0]) + y * sizeof(a[0][0]))
where sizeof(a[0]) is == sizeof(int) * 10.quick edit: added a (char *) cast so the arithmetic doesn't multiply by sizeof(int) again
Of course, sometimes you do want an array of arrays, such as when each array needs to have a different length or element type – which you can of course do. Which is why I'm a bit confused about how having support for multidimensional arrays is a problem. If you find them confusing, why not just ignore the feature and use arrays of arrays all the time?
I'm also not clear on what "special treatment by the compiler" means.
The standard lib and 3rd party libs use multi-d arrays, so I can't avoid them. But I guess it takes some time to get used to.
> I'm also not clear on what "special treatment by the compiler" means.
I meant something like saving an array of arrays into a continuous memory block and somehow enforcing that the sub-arrays must have equal length. But now I realize that this is probably impossible...