Compelled to use the variable length array feature for my auxiliary function that prints square matrices, I defined it as follows:
void print_matrix(M, dim)
unsigned dim;
int M[dim][dim];
{
/* Print the matrix here. */
...
The good news is, the code works and has its parameters in the order I'd like them to be.
The bad news is, I had to use the "old-style" function declaration syntax in order to reference the yet-to-be-declared argument dim
in the declaration of M
, which is apparently considered obsolete and dangerous.
Is there a straightforward way to do the same with the "new-style" function declarations WITHOUT changing the order of the parameters? (And if not, is it considered acceptable use of the old-style syntax in this particular situation?)
void print_matrix(unsigned dim, int (*M)[dim][dim])
. You're printing a 3D array, of course. – Hobson-Wpedantic-errors
, you'd get compilation errors. Certainly, K&R compilers did not support VLA notation. There's a moderate chance you're using GCC and it is providing extensions that allow it to work. – Hobson-std=c11 -pedantic-errors
, but great point about the compatibility, of course. Even if the standard does not explicitly prohibit it (or so it seems), it's probably going to be poorly tested on the GCC/Clang side and non-idiomatic. I'm just surprised you can do that at all, to be honest. – Cathodegets()
function even though it has not been part of the standard since 2011, and was marked deprecated in TC3 for C99). – Hobsonsizeof
no longer constant, and decreeing that code which puts size parameters after array pointers is somehow defective flies directly in the face of the first two Spirit of C principles. – Petrie