本文介绍了静态VS全球的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有像下面C文件,之间有什么区别 I
和Ĵ
?
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;静态INT I;
诠释J;诠释的main()
{
//执行一些
}
解决方案
I
的内部连接,所以你不能使用名称 I
在其他源文件(严格翻译单元)来指代相同的对象。
Ĵ
有外部链接,那么你可以使用Ĵ
来引用此对象,如果你把它声明的extern
在另一个翻译单位。
If I have a C file like below, what is the difference between i
and j
?
#include <stdio.h>
#include <stdlib.h>
static int i;
int j;
int main ()
{
//Some implementation
}
解决方案
i
has internal linkage so you can't use the name i
in other source files (strictly translation units) to refer to the same object.
j
has external linkage so you can use j
to refer to this object if you declare it extern
in another translation unit.
这篇关于静态VS全球的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!