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

跟風遠走 提交于 2019-12-24 01:47:39

问题


6.7.6 Declarators says

Each declarator declares one identifier, and asserts that when an operand of the same form as the declarator appears in an expression, it designates a function or object with the scope, storage duration, and type indicated by the declaration specifiers.

And also states about syntax of parameter:

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

For the given function prototype

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

int a[] declares a parameter with declarator a[] which declares an identifier a.


While in case of

int f( int [], int n);

int [] declares parameter is an array of int with no identifier.
Is [] also a declarator ? ( I think no because it doesn't declare an identifier but syntax for parameter says it is!)


回答1:


In the identifier-less parameter declaration, you have an abstract declarator. That is, the [] in int f(int [], int n) is an abstract declarator for the array. You can find more in sections §6.7.6 Declarators and §6.7.7 Type names in ISO/IEC 9899:2011 (the C11 standard).



来源:https://stackoverflow.com/questions/17793829/is-also-a-declarator-when-used-in-parameter-declaration-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!