为什么C允许空声明?语法级别都明确允许它们使用,并且仅在编译时才生成警告。
生产declaration,从C标准的附件A中,允许它在语法级别:
declaration
= declaration_specifiers , ";"
| declaration_specifiers , init_declarator_list , ";"
| static_assert_declaration
;
Run Code Online (Sandbox Code Playgroud)
(EBNF由我变成)
C不允许空声明。参见/sf/answers/2329164421/
但是它的确允许声明而没有任何声明符,只有声明符,只要那些声明符创建类型标记即可。例如:
/* here begins the specifier */
struct tagS /* <-- there's the tag */
{
int x;
} /* here ends the specifier */
/* no declarators */
;
Run Code Online (Sandbox Code Playgroud)
这是定义用户定义类型的结构的一种非常有用且合法的方法。
这就是为什么语法必须将声明符列表指定为可选的原因。