免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: tajial
打印 上一主题 下一主题

[C] 全局变量是否会自动初始化为0? [复制链接]

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
11 [报告]
发表于 2010-07-31 18:03 |只看该作者
与C标准无关
beepbug 发表于 2010-07-31 17:41

c99 6.7.8-10
If an object that has automatic storage duration is not initialized explicitly, its value is
indeterminate. If an object that has static storage duration is not initialized explicitly,
then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules;
— if it is a union, the first named member is initialized (recursively) according to these rules.

c89 6.5.7
If an object that has automatic storage duration is not initialized explicitly. its value is
indetelminate.74) If an object that has static storage duration is not initialized explicitly. it is
initialized implicitly as if every member that has arithmetic type were assigned 0 and every
member that has pointer type were assigned a null pointer constant.

74 Unlike in the base document. any automatic duration object may be initialized

论坛徽章:
0
12 [报告]
发表于 2010-08-02 07:26 |只看该作者
这个,你得先弄清楚UNIX与C的关系,就不会理解偏了。

论坛徽章:
2
15-16赛季CBA联赛之四川
日期:2016-04-23 14:25:46操作系统版块每日发帖之星
日期:2016-05-09 06:20:00
13 [报告]
发表于 2010-08-09 10:41 |只看该作者
同意6樓的,初始化全局變量會增大可執行文件的大小,
沒有好處

论坛徽章:
0
14 [报告]
发表于 2010-08-12 13:18 |只看该作者
肯定清零,规范里有

而且可以省rom
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP