Global variables are slower?

John Wehle john@feith.com
Fri Feb 11 16:40:00 GMT 2000


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

No.  Consider:

int i;
int *p;

int main()
  {
  int a;

  for (i = 0; i < 1000000; i++)
    {
      *p = i + 1;
      a += i;
    }
  }

p might point to i.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------



More information about the Gcc mailing list