This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Global variables are slower?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]