A little background:
As others have pointed out, static variables are have internal linkage, which means that they can only be used in the same "compilation unit" or source file. That means you cannot declare it in a header file, assign a value to it in one compilation unit, and expect that value to appear in another.
When you initialize a global variable (static or not), the compiler simply puts the initial value into the executable file at the memory location allocated for the variable. In other words, it always has an initial value. Of course you can always override the value later by using an assignment statement.
Suggestions:
If you really don't know the value of the variable at compile-time, then you should assign it dynamically in your initialization function.
static some_type some_variable; /* = 0 by default */
/* some code */
void MyInitializations()
{
some_variable = some_value;
}
If you want to declare the variable in one place, say a header file, and define it in a source file, then you should use an 'extern' declaration which tells the compiler to not worry about where the variable is. The linker will find the location of the variable much like it finds a function in another file and fill in the address.
Header:
extern some_type some_variable;
Source file 1:
void UseSomeVariable()
{
x = some_variable;
}
Source file 2:
some_type some_variable = some_value;
/* possible also uses some_variable */
If you just want to declare the variable in one place and define it in another, don't use the 'static' keyword. The downside of this is that you can't use the same global variable in different compilation units (.c files) and you can't use it in a header file.