考虑这些例子:
static int a;
extern int a; //OK -- what linkage does the a have now?
static int a;
int a; //ERROR
extern int a;
static int a; //ERROR
int a;
static int a; //ERROR
extern int a;
int a; //OK as expected
int a;
extern int a; //OK as expected
为什么在第一个示例中可以,而在第二个示例中则不行?
就文件范围变量(全局范围)而言,当没有指定关键字时,它们具有外部链接和静态持续时间。
谢谢
AFAIK,功能的链接和存储持续时间有点不同。
编辑:我尝试使用 gcc 4.5.2 -Wall -pedantic --std=c99 进行编译
更多信息:http ://c-faq.com/decl/static.jd.html您可以看到第一个示例也可以在那里工作,但第二个没有。但是,我看不出是什么让它们如此不同。