R
root
Hi
I have a function called many times. It has a loop and I declare the
index variable as a "register int" to let the compiler know that it is
heavily used and should be optimized.
Now I need to modify the function and include a call in some loop
iterations to another function that will take a pointer to the loop index.
My question is: which will be more efficient?
(1) keep the register specifier and copy the variable to a non-register
variable when needed:
register int x;
int xcopy;
// ... (work with x)
xcopy = x;
function(&xcopy);
// ... (work with x)
or
(2) just use a single non-register variable:
int x;
// ...(work with x)
function(&x);
Thanks.
PS. In option (1) is it an undefined behavior to do
function(&(xcopy = x));
?
I have a function called many times. It has a loop and I declare the
index variable as a "register int" to let the compiler know that it is
heavily used and should be optimized.
Now I need to modify the function and include a call in some loop
iterations to another function that will take a pointer to the loop index.
My question is: which will be more efficient?
(1) keep the register specifier and copy the variable to a non-register
variable when needed:
register int x;
int xcopy;
// ... (work with x)
xcopy = x;
function(&xcopy);
// ... (work with x)
or
(2) just use a single non-register variable:
int x;
// ...(work with x)
function(&x);
Thanks.
PS. In option (1) is it an undefined behavior to do
function(&(xcopy = x));
?