Is [] also a declarator (when used in a parameter declaration) in C?

6.7.6 declarants says

Each declarator declares one identifier and states that when the operand is of the same form, as the declarator appears in the expression, it denotes a function or object with the volume, storage duration and type specified by the declaration qualifiers.

It also indicates the parameter syntax:

parameter-declaration: declaration-specifiers declarator declaration-specifiers abstract-declarator(opt) 

For a prototype of a given function

 int f( int a[], int n); 

int a[] declares a parameter with the declaration a[] , which declares the identifier a .


While in case

 int f( int [], int n); 

int [] declares parameter is an int array with no identifier.
Is [] also a declarator? (I think not, because it does not declare an identifier, and the syntax for the parameter says it!)

+2
source share
1 answer

In a parameter declaration without an identifier, you have an abstract declarator. That is, [] in int f(int [], int n) is an abstract declarator for an array. You will find more details in sections ยง6.7.6 declarators and ยง6.7.7 Type names in ISO / IEC 9899: 2011 (standard C11).

+6
source

Source: https://habr.com/ru/post/975903/


All Articles