【发布时间】:2016-05-18 08:44:28
【问题描述】:
代码先行:
#include <stdio.h>
void foo()
{
static int bar;
}
int main()
{
bar++;
return 0;
}
编译器(Clang)抱怨:
static.c:10:2: error: use of undeclared identifier 'bar'
foo() 中的声明 static int bar; 不应该给 bar 静态存储持续时间,这使它在 main 函数之前声明和初始化吗?
【问题讨论】:
-
可以,但不在
main的范围内。 -
存储持续时间与范围/可见性有什么关系?
-
一旦问题中的问题得到回答,请不要添加其他问题。我正在回滚添加。如果您不同意,请告诉我们。
标签: c static scope declaration