什么是全局变量的默认存储类? [英] What is default storage class for global variables?

查看:207
本文介绍了什么是全局变量的默认存储类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全局变量的默认存储类是什么?

What is default storage class of a global variable?

在web上搜索时,我发现一些网站说它是 static 。但是,静态意味着内部链接和变量不能在文件范围外可用,即它不应该可用于其他目标文件。但是,仍然可以使用 extern int i 的声明访问其他文件。

While searching on web I found, some sites say it is static. But, static means internal linkage and the variable can not be available outside the file scope i.e it should not be available to other object files. But, they still can be accessed to other files using declarations like extern int i.

static 到全局变量,然后在文件范围之外不可用。

And, if I explicitly mention static to global variable then it is not available outside the file scope.

然后,什么是正确的默认存储类的全局变量?

Then, what is correct default storage class for the global variables?

推荐答案

默认存储持续时间是静态的,你不是唯一的一个,发现它有点混乱。 C书(始终是一个很好的参考)说:

The default storage duration is static, but default linkage is external. You're not the only one to find it a bit confusing. The C Book (always a good reference) says:


你可能会发现这些不同元素之间的交互
是复杂和混乱的:
,因为它们是!

"You'll probably find the interactions between these various elements to be both complex and confusing: that's because they are!"

具有该报价的部分,声明,定义和辅助功能,有一个有用的表(8.1)。最后一行描述了您感兴趣的情况。值得注意的是,没有存储类说明符的数据对象具有外部链接和静态持续时间。

The section with that quote, Declarations, Definitions and Accessibility, has a helpful table (8.1). The last row describes the case you're interested in. As it notes, data objects with no storage class specifier have external linkage and static duration.

这篇关于什么是全局变量的默认存储类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆