C11标准在第6.7/5节中规定哪些声明也是定义:
C11 6.7/5
标识符的定义是该标识符的声明:
- 对于一个对象,导致为该对象保留存储;
(......)
那么块内变量的声明也是一个定义吗?例如:
void Bla(void) {
int a; // Is this declaration also a definition?
}
Run Code Online (Sandbox Code Playgroud)
我在stackoverflow上找到了以下两个答案,其中声明块内变量的声明也是定义:
但是,"Michael Burr"提供的答案是指6.2.2/2"标识符的链接",以便解释块范围内的变量声明也是定义.对我来说,他的参考不回答我的问题.第二个链接中的答案未提供对C标准的任何引用.C标准中是否还有其他段落可用作确认答案的参考?
请提供C标准的参考.
ANSI C语法指定:
declarator:
pointer_opt direct-declarator
direct-declarator:
identifier
( declarator )
direct-declarator [ constant-expression_opt ]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list_opt )
Run Code Online (Sandbox Code Playgroud)
根据这个语法,可以推导出来
func()()
Run Code Online (Sandbox Code Playgroud)
作为宣告者,和
int func()()
Run Code Online (Sandbox Code Playgroud)
作为声明,在语义上是非法的.为什么C语法允许这种语法上合法但非法的非法声明?