In a parameter declared as an array of arrays, the C standard defines static
only in the first dimension, and that is the only dimension you need it in.
C 2018 6.7.6.2 1 says:
… The optional type qualifiers and the keyword static shall appear only in a declaration of a function parameter with an array type, and then only in the outermost array type derivation.
static
is useful because the outermost dimension otherwise would be lost. The parameter declaration int a[3][6]
is automatically adjusted to int (*a)[6]
, which is a pointer to an array of 6 int
, but there is no information about how many arrays of 6 int
are at that location.
int a[static 3][6]
is also adjusted to int (*a)[6]
but with the additional information that there should be at least 3 arrays of 6 int
at that location.
There is no need for static
on the second dimension because the information about the second dimension is not lost. int [6]
is a complete type; it is an array of 6 int
. If we have a pointer to one array of 6 int
, there are 6 int
there. If we have a pointer to three arrays of 6 int
, there are 3 arrays of 6 int
there (18 int
total).
[6]
, or can be defined variably e.g.[cols]
assuming the expressioncols
can be evaluated and the implementation supports pointers to variable length arrays.static
means "at least". The compiler cannot calculate address ofarr[1]
if it doesn't know how largearr[0]
is. Something like "at least xy bytes" is not useful here.