小编Sin*_*kus的帖子

块内的变量声明也是一个定义吗?

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标准的参考.

c declaration definition language-lawyer c11

4
推荐指数
1
解决办法
178
查看次数

ANSI C - 直接声明符语法 - 为什么C语法允许语法合法但非语义上非法的声明,如int func()()?

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语法允许这种语法上合法但非法的非法声明?

c syntax grammar declaration c89

1
推荐指数
1
解决办法
244
查看次数

标签 统计

c ×2

declaration ×2

c11 ×1

c89 ×1

definition ×1

grammar ×1

language-lawyer ×1

syntax ×1