I\'ve seen the word static
used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?
static
means different things in different contexts.
You can declare a static variable in a C function. This variable is only visible in the function however it behaves like a global in that it is only initialized once and it retains its value. In this example, everytime you call foo()
it will print an increasing number. The static variable is initialized only once.
void foo ()
{
static int i = 0;
printf("%d", i); i++
}
Another use of static is when you implement a function or global variable in a .c file but don't want its symbol to be visible outside of the .obj
generated by the file. e.g.
static void foo() { ... }