为什么这没有给出编译错误? [英] Why doesn't this give compilation error?

查看:73
本文介绍了为什么这没有给出编译错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int a = a ;  

根据赋值运算符的规则,应从右到左读取该行.看到"a"后,未声明的编译器应给出编译错误.
但是它给出了垃圾值.请澄清一下.

According to the rule of assignment operator it should read the line from right to left. After seeing 'a' undeclared compiler should give compilation error.
But it is giving garbage value . Please Clarify it .

推荐答案

实际上,编译器可能会给您提示.我的话说:警告C4700:未初始化就使用了局部变量'a'".

Actually, compiler might give you a hint. Mine says: "warning C4700: local variable 'a' used without having been initialized".

但这本身并不是错误,声明只是将变量名赋予了存储器的某些位,而没有涉及它,这是有效且快速的.而且这里的分配并不是真正的分配,只是从右向左移动位.不再检查.非常有生产力,非常不安全.

But this is not an error per se, declaration just gives a variable name to some bits of memory without touching it, which is valid and fast. And the assigment here is not really an assigment, just moving bits from right to left. No checks again. Very productive, very unsafe.

每个操作都是合法的,但整个操作毫无意义.因此,编译器会尽其所能-编译代码,但也会发出警告.

Every operation is legal, but the whole thing is pointless. So compiler does the best thing it can - it compiles the code, but gives a warning too.

这篇关于为什么这没有给出编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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