为什么C ++编译器不能将每个整数声明初始化为0,无论是局部还是全局或成员? [英] Why do C++ compilers not initialise every integer declaration to 0, be it local or global or a member?

查看:126
本文介绍了为什么C ++编译器不能将每个整数声明初始化为0,无论是局部还是全局或成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我很奇怪为什么C ++编译器不会将每个整数声明初始化为0,无论是局部还是全局或成员?为什么未初始化的部分存在于内存模型中?

It baffles me why C++ compilers do not initialise every integer declaration to 0, be it local or global or members? Why do uninitialised sections exists in the memory model?

推荐答案

我知道这是一个愚蠢的答案,

I know it's a dull answer, but your question begs for it exactly:


因为C ++标准如此。

Because the C++ standard says so.

为什么这样说?因为C ++建立在一个原则上:

Why does it say so? Because C++ is built on a principle:


不支付你不使用的东西。

Don't pay for what you don't use.

将内存设置为某个值会耗费CPU时间和内存带宽。如果你想做,明确做它。变量声明不应产生此成本。

Setting memory to a certain value costs CPU time and memory bandwidth. If you want to do it, do it explicitly. A variable declaration should not incur this cost.

这篇关于为什么C ++编译器不能将每个整数声明初始化为0,无论是局部还是全局或成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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