* Tony Johansson:
I know it's bad design to use global variables. I just want to ask a
question about them.
Is global variables and global static variables the same. These are define
outside any function at the top of the a file where you have them.
This is not primarily a language question but a terminology question.
With respect to a some piece of C++ source code S a variable is "global"
if it's available in all of S plus possibly in code outside S, and it's
"local" if it's only available within S, possibly not within all of S.
I.e.,
"local" => inside only
"global" => all of inside + possibly also outside
Used without qualification the meaning is somewhat language dependent; in
C++ unqualified "local" usually refers to S = a function, and unqualified
"global" usually refers to S = a translation unit, then meaning a variable
that's not only available throughout S but also outside S, in all units.
With that default in place, a "global variable" (unqualified) means a
variable available throughout the whole statically linked program, S =
compilation unit, whereas a "global static variable" (qualified) means
a variable available throughout a single compilation unit, S = the code
from the variable declaration to the end of the compilation unit text.
In standard C++ available throughout the complete statically linked program
is the most global a variable can be.
In in-practice C++ it's possible for a variable to be even more global,
exported to dynamically linked libraries.