T
Todd Blackmon
The one major beef I have with C/C++ is that there are so many variations
for
the same word. For example:
static global variable - variable accessible only from within source
file
static function - function accessible only from within source
file
static variable in function - variable whose value gets retained between
calls
static member variable - variable with one value for all classes
static member function - function accessible from outside the class
I think you are just looking at it wrong. Ignoring the last two
because they are C++ only, for C static *is* consistent.
Static explicitly defines two things about an identifier (function or
variable): 1. scope, 2. lifetime.
Scope
If static is inside a function, it is function-scoped, otherwise it is
file scoped.
Lifetime
The identifier exists for the entire life of the program.
That's it, no more. But what makes it seem different is that the
default scope and lifetime rules are different for global variables,
functions, and local variables. This makes static to appear to mean
different things, but it really doesn't.
tjb