News for hackers. Stuff that matters.
Re:Fortran is still a thing by int_19h on Tuesday November 27, 2018 @11:06PM (#18549219)
An array of arrays is necessarily contiguous in C - this is implied by the type. An array of pointers to arrays will, of course, not be contiguous - and is the only way to get a dynamically sized heap-allocated 2D array in C (VLAs give you stack-allocated arrays, with all the size limits that entails).

In C++, this all is best handled by a library class.

Re:Fortran is still a thing by cygx on Wednesday November 28, 2018 @04:09AM (#18550215)
Heap-allocated dynamically-sized NxM matrix in C99:

    double (*mat)[M] = calloc(N * M, sizeof (double));
Re:Fortran is still a thing by int_19h on Wednesday November 28, 2018 @04:26AM (#18550282)
Ah, good point. I always forget that VLA types in C99 are actually types, and so you can use them in these contexts as well.

It's a shame they killed VLAs as a mandatory language feature. They didn't make C into Fortran (which I think was the hope, between them, complex numbers, and "restrict"?), but they did make some things a great deal more pleasant to write.

Re:Fortran is still a thing by cf498 on Wednesday November 28, 2018 @03:33AM (#18550071)
>and is the only way to get a dynamically sized heap-allocated 2D array in C (VLAs give you stack-allocated arrays, with all the size limits that entails).

Why wouldnt you be able to create a dynamic array of arrays with placement new and a cast.

Re:Fortran is still a thing by int_19h on Wednesday November 28, 2018 @04:24AM (#18550271)
A cast to what, though? You need to be able to write the type of that array, but you can't do that unless dimensions are compile-time constants.