I have been thinking of a couple of possible extensions to the C language which I'd like to know the opinion of others about.1 This one is about multi-dimensional arrays.Imagine the following situation in C:void matrix_mul(double **res, double **a, double **b, size_t n, size_t m, size_t r);You cannot pass a double mat[4][4] (for example) to this function. If you define the function as:void matrix_mul_N_M_R(double res[N][R], double a[N][M], double b[M][R]);You'd just be wasting a perfectly written fine algorithm on a certain size of matrices.What came to me (in shower obviously), was decay of multi-dimensional arrays to multi-level pointers. This is an extension to decay of 1d arrays to pointers.Semantically, this would allow the first type of function to work on any two-dimensional array. Technically, this is how it would be implemented. The following code:double a[3][5];double b[5][4];double c[3][4];...matrix_mul(c, a, b, 3, 5, 4);would be equivalent to:double a[3][5];double b[5][4];double c[3][4];...double **__a_decay = {a[0], a[1], a[2]};               /* generated by compiler */double **__b_decay = {b[0], b[1], b[2], b[3], b[4]};   /* generated by compiler */double **__c_decay = {c[0], c[1], c[2]};               /* generated by compiler */matrix_mul(__c_decay, __a_decay, __b_decay, 3, 5, 4);  /* first three arguments decayed */Is the application for such an extension very limited? Are there pitfalls? Could this possibly lead to insecure code where not using this feature wouldn't? Where else could such a feature come in handy?1 Note that I'm not going to make another language myself, but would like to be sure of the feature's benefits and pitfalls before trying to suggest them to the C Standard Committee.
What could be the advantages and disadvantages of decay of Nd arrays to N-level pointers?
c;language design
How would your proposed extension handle the situation where a multi-dimensional array isn't allocated statically?  Having the extension be limited to cases where the allocation is static would make its behavior inconsistent with other array handling, but if the extension isn't limited to static array allocations then passing a double[5000][5000] to function which is expecting a double** would require the compiler to generate and fully populate a (double*)[5000], even if the function wouldn't use most of (or even any of) its elements each time the function was called.A more useful extension might be to add types like double[][] and double[][][] as types in the language, and have each such type with N dimensions be stored as a double* along with N-1 values of type type size_t.  It would be necessary to have separate methods for jagged and linear arrays, but it would not be necessary to have different methods for each size of linear array.