global static vs global??

M

Mark

Hi,

So I came across some source code... "static int slices = 16;" which
is outside of any class or function. I know what statics are used for
inside classes/functions, but what does it mean if it's global?
Perhaps my C++ is getting a bit rusty...
 
M

Mark

Hi,

So I came across some source code... "static int slices = 16;" which
is outside of any class or function. I know what statics are used for
inside classes/functions, but what does it mean if it's global?
Perhaps my C++ is getting a bit rusty...

nvm... my girlfriend found the answer (out of all people!). I guess
my googling skills are getting a bit rusty too:

A static global variable is never visible outside of its file, even
in the presence of ``extern'' declarations. global variable is a
variable that is accessible in every scope
 
J

Jim Langston

Mark said:
nvm... my girlfriend found the answer (out of all people!). I guess
my googling skills are getting a bit rusty too:

A static global variable is never visible outside of its file, even
in the presence of ``extern'' declarations. global variable is a
variable that is accessible in every scope

Yes, just to give you a little more information, it's not necessary that
"file" but that "translation unit". So a file that is included could still
see the same instance of the variable because its the same "translation
unit". A translation unit is a group of files that gets compiled to an
object file. Normally, but not always, this is one .cpp with whatever
header files it includes. At the end of compiling the translation units
(which are now object files) get linked together to form an executable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top