Apparently the following function prototypes are valid in C99 and C11:
void foo(int a[const *]);
void bar(int a[static volatile 10]);
What is the purpose of those strange subscript notations *
, static
, and CV qualifiers?
Do they help distinguish statically typed arrays from variable-length arrays? Or are they just syntactic sugar?
static in parameter array declarator
static
here is an indication that parametera
is a pointer toint
but that the array objet (wherea
is a pointer to its first element) has at least10
elements.A compiler has then the right to assume
f
argument is notNULL
and therefore it could perform some optimizations.gcc
currently performs no optimization (source):qualifier in parameter array declarator
inside
g
a
is a cvr pointer toint
(cvr isconst
,volatile
orrestrict
qualifier). For example, withconst
it meansa
is aconst
pointer toint
(i.e., typeint * const
).So a parameter declaration:
is the same as a parameter declaration:
* in parameter array declarator
The
[*]
in a formal array parameter declaration in a function declaration (that is not part of a function definition) indicates that the formal array is a variable length array.