static和extern的混合用法测试

来源:互联网 发布:大众网络报官方网站 编辑:程序博客网 时间:2024/05/15 07:51
//static_global.cstatic int good = 234;int luck = 123;

//main.c#include <stdio.h>extern int good;extern int luck;int main(){    //printf("%d", good);//  main.o:main.c:(.text+0xf): undefined reference to `_good'     printf("%d", luck);//the output is 123}


 

/*测试结果表明,C代码文件中用static声明的变量,不可以在别的C代码文件中使用extern来引用的。声明为auto类型(默认auto这个关键词是省略的)的变量,看在别的C代码文件中通过extern来引用的。*/