by rseacord · 6y ago · 0 comments
double (*a)[N][P] = (double (*)[N][P])a_flat;
for (i=0; i<M; i++)
for (j=0; j<N; j++)
for (k=0; k<P; k++)
a[i][j][k] = f(i, j, k);
The alternative would be a_flat[(i*M+j)*P+k] = f(i, j, k);
which is a lot more error-prone. I understand that some implementation (MSVC) declined to implement VLAs, but I really wish that at least VLA-pointers could have remained a mandatory part of C11 and later standards.[
] Has there been any discussion of adding GCC's "typeof" to the standard?