peetm said:
Hello:
I am trying to understand the use of static in this program.
http://nanocrew.net/sw/nscdec.c for "inverse" matrix.
What difference would it make if it were not static and just "const
unsigned char inverse[ 128 ]" in global space which it already is ?
Of course [it's like a lot of things in C], static is used for a few things.
For things that would be 'global' (external linkage?) without using it,
static gives them file scope - that's the case here.
For local variables [within a function], static essentially gives the
variable the same storage *as though* it were declared outside of a
function, i.e., its value is retained for the life of the program. However,
it also restricts the variable's visibility - to that of the function in
which it was defined.
No. An object defined in a function, static or not, is never visible
outside of the function.
The static qualifier is precisely two things in C. A storage class and a
linkage limiter. First, storage class. All objects defined outside of
any function (at file scope) have static storage class. That means that
the compiler allocates space for it and that it exsists for the life of
the program.
Other variables defined within functions default to automatic storage
class and cease to exist when the function returns. We can define an
object in a function with the 'static' qualifier. This gives the object
static storage class, meaning it is allocated by the compiler and lives
for the life of the program.
Because objects at file scope have static storage class by default, the
static keyword can take on another meaning. Also by default, objects and
functions defined at file scope enjoy external linkage, meaning they can
be 'seen' by the linker and therefore used by other modules in the
program. Now here at file scope, we can qualify an object as 'static'
and block its otherwise external linkage. The object or function is no
longer visible to the linker and therefore cannot be used by other modules.