News for hackers. Stuff that matters.
Re:Julia 0.2 released by zwegner on Sunday November 17, 2013 @03:15PM (#6750624)
I'm confused about your reference to C. C has multidimensional arrays, and all the elements are laid out contiguously in memory. No index calculations are needed, it's all done by the array indexing operation.

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

Re:Julia 0.2 released by StefanKarpinski on Sunday November 17, 2013 @05:09PM (#6751221)
Right, I should have clarified. That works for statically allocated arrays but not for dynamically allocated ones. Since matrix dimensions are generally not known ahead of time, in real programs you almost always end up needing to simulate multiple indices using explicit index arithmetic.