问题描述
我有点好奇C和C ++如何处理未存储在变量的数据,例如:
INT IE6_Bugs = 12345;
INT Win_Bugs = 56789;
是的 - 一切都清楚了。 IE6_Bugs
已经存储了它的特定的内存地址123456。
那么关于..
如果(IE6_Bugs + Win_Bugs> 10000)
{
// ...
所以C抓住两个变量的值,并将它们以比较的结果到右边的中间体
不过:
-
确实
IE6_Bugs + Win_Bugs
曾经达到RAM?还是处理器直接的值通过其自己的高速缓存相比如何? -
或者是,在编译过程中,上面的if语句转换成一些更理解为机? (也许计算
IE6_Bugs + Win_Bugs
第一,它存储在某个变量,...)
这将被放置在一个寄存器中的CPU(假定有一个可用)。寄存器是一种超高速超小型RAM的内置到了CPU内部,并用于中间业务的商店的结果。
如果能确定的值总是等于XXX那么聪明的编译器将取代它的位置XXX的价值。
请记住,不管它是作为一个前pression或数字,(X + Y对10),它会的还是的需要被放置在一个寄存器,使得CPU可以根据其价值进行访问和执行操作。
有关更多信息,计算机体系结构读了。
I'm a bit curious about how C and C++ handle data which isn't stored in variables, e.g:
int IE6_Bugs = 12345;
int Win_Bugs = 56789;
Yeah - everything clear. IE6_Bugs
has 123456 stored at it's specific memory address.
Then what about..
if ( IE6_Bugs + Win_Bugs > 10000 )
{
// ...
So C grabs the values of the two variables and adds them in order to compare the result to the int on the right.
But:
Does
IE6_Bugs+Win_Bugs
ever reach RAM? Or does the processor directly compare the values via its own cache?Or is, in the compiling process, the above if statement converted to something more "understandable" for the machine? (Maybe calculate
IE6_Bugs+Win_Bugs
first and store it in some variable,...)
It'll be placed in a register in the CPU (assuming one is available). A register is a sort of super-fast super-small RAM that's built into the CPU itself and used to store results of intermediate operations.
If the value can be determined to always equal xxx then a smart compiler will substitute the value of xxx in its place.
Keep in mind that regardless of whether it is as an expression or a number, (x+y vs 10) it will still need to be placed in a register so that the CPU can access it and perform an operation based on its value.
For more info, read up on computer architecture.
这篇关于什么C(++)做未存储在变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!