This question already has an answer here:
I am writing a custom C99 parser. I got the grammar from this link. This grammar says following is a valid syntax for declaring arrays -
int arr[*];
Relevant part of the grammar is follwing -
direct-declarator ::=
identifier
"(" declarator ")"
direct-declarator "[" type-qualifier-list? assignment-expression? "]"
direct-declarator "[" "static" type-qualifier-list? assignment-expression "]"
direct-declarator "[" type-qualifier-list "static" assignment-expression "]"
direct-declarator "[" type-qualifier-list? "*" "]"
direct-declarator "(" parameter-type-list ")"
direct-declarator "(" identifier-list? ")"
I tried compiling a code with this declaration using gcc. It gave me following warning -
error: ‘[*]’ not allowed in other than function prototype scope
So I tried declaring a function prototype with this type of syntax and it compiled without any error or warning. What I am not getting is what can this syntax possibly mean semantically. Any expert with an explanation?
It's a declarator for a variable length array with unspecified size. Furhtermore, the following declaration
void func(size_t n, char s[n]);
is equivalent to simply writing:
void func(size_t n, char s[*]);
The above is particularly useful for writing headers, where you'd normally declare only the parameter types
void func(size_t, char [*]);
来源:https://stackoverflow.com/questions/42325958/what-does-asterisk-inside-square-bracket-of-array-declaration-mean-in-c