Global variables are slower?
Jeffrey A Law
law@cygnus.com
Fri Feb 11 15:11:00 GMT 2000
In message < 2473C7ACA21ED211854F08002BB768C40551D066@OZ >you write:
> Good point about the optimization suggested! I was talking about the best
> optimization, i. e. transform the program to:
>
> printf("882236160\n");
>
> on the i686, and appropriately on other platforms.
>
> Is it correct to summarize that if there are no function calls between
> repeated references to a non-volatile global variable, then it can be
> optimized to work as well as a local variable. Otherwise, global variables
> require extra instructions for access?
No, that is not a safe assumption.
For example, local variables are subject to register allocation (ie, they
can be easily held in a register). The same is not generally true for globals,
so they often end up in memory.
jeff
More information about the Gcc
mailing list