Global variables are slower?

Dima Volodin dvv@egcs.dvv.ru
Fri Feb 11 14:26:00 GMT 2000


On Fri, 11 Feb 2000 17:15:46 -0500, you wrote:

>Hello folks,
> 
>Somebody told me that accessing a global variable requires an extra
>instruction, and thus, global variables are slower than local variables.

It depends on the architecture you run your program on.

>Is this true for gcc generated code? I'm surprised if it is because I
>understood from my knowledge of C that there was no performance difference
>between local and global variables.

Your understanding of your knowledge of C is wrong. Or your knowledge of
C is wrong. Or both.

>Can it be optimized out, at least for repeated accesses, if it is true?

It can and it is.

>Anjul.

Dima


More information about the Gcc mailing list