为什么C标准休假使用不确定的变量未定义? [英] Why does the C standard leave use of indeterminate variables undefined?
本文介绍了为什么C标准休假使用不确定的变量未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在哪里垃圾存储的价值,出于什么目的?
Where are the garbage value stored, and for what purpose?
推荐答案
,C选择不初始化变量,为了提高效率,一些自动的价值。为了初始化这个数据,指令必须加入。这里有一个例子:
C chooses to not initialize variables to some automatic value for efficiency reasons. In order to initialize this data, instructions must be added. Here's an example:
int main(int argc, const char *argv[])
{
int x;
return x;
}
生成:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl -4(%ebp), %eax
leave
ret
虽然这code:
While this code:
int main(int argc, const char *argv[])
{
int x=1;
return x;
}
生成:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $1, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
正如你所看到的,一个完整的额外的指令是用来移动1成的X.这曾经无所谓了,仍然没有在嵌入式系统中。
As you can see, a full extra instruction is used to move 1 into x. This used to matter, and still does on embedded systems.
这篇关于为什么C标准休假使用不确定的变量未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文