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_Bugsever 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_Bugsfirst 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.