On Sun, 02 Sep 2007 17:01:11 -0700, Chad <cd*****@gmail.comwrote:
>I'm not too sure if this is the right forum to ask the following
question.
Given the following code
#include <stdio.h>
int main(void)
{
int a=5;
int b=6;
int c, i;
for(i=0; i< 30; i++) {
c = a * b;
}
return 0;
}
Now let's assume the values of a and b never change. Each time the
'for' loop executes in the above code, a and b gets multiplied. If I
would change the value of c to register, would the values of and b get
cached? Ie not get re-loaded into the memory everytime the for loop
gets executed.
The C language doesn't know from cache. Whether a value is cached is
a question usually beyond the compiler/linker/run time library, the
things we usually discuss here.
Does the hardware have cache? How much? Does the operating system
support it efficiently? What else is running on the system at the
time this code is running? Is the code generated by the compiler
"cache-friendly"?
None of these questions are affected by presence or absence of
"register". It is entirely possible that adding register would cause
data that would normally be cached during execution to not be.
By the way, most modern compilers with a decent optimizer will ignore
register when you specify it.
Remove del for email