Global statics
Any variables declared outside the body of a function are visible to all
functions which follow the declaration in that file. They are global in
their scope. They are all permanent, since they have no function whose
calling leads to their creation and whose termination leads to their
deletion. The extra word static is not needed. If you do not use it,
however, they become externally visible.
This only matters if you are building libraries, but it is best to use the
static specifier unless you definitely want the variable to be external.
Only variables which have to remember important shared values should
normally be declared in this way, since they can cause confusing name
clashes. If a function uses a local variable with the same name as a
global, the name refers to the name inside the function. If you forget
this and try to access the global variable, the effect may not be what you
intended. It is also dangerous since the value may change unpredictably as
far as any one function is concerned. If you need to use global statics
use names which are unlikely to be confused with local variables and whose
intended use is clear.
Next - External items.
Back to Contents page.