VC6.0,c语言extern声明一个static全局变量,链接不通过
程序很简单,是测试static和extern的用法,代码如下:
#include<stdio.h>
void f1()
{
extern i;
i=i+1;
printf("%d\n",i);
}
static int i=4;
void main()
{
f1();
f1();
f1();
}
编译通过,链接报错:error LNK2001: unresolved external symbol _i
按理说,static定义静态全局变量,应该是可以被本文件内的函数调用的,我在f1()函数中进行了extern声明,编译都没问题,为什么会出现链接错误呢??另外,把static去掉,直接定义int i,则能正确链接和运行。恳请大神指点迷津啊!