Because an internal static variable can only be initialized by the compiler, we need another mechanism to safely store a value that we might want to initialize, or seed, ourselves. For this, we can use an external static variable.
External static variables can only be accessible by any other variable or code block, including function blocks, within the file where it is declared. Ideally, then, the code for the external static variable and the function that accesses it should be in a single, separate .c file, as follows:
// seriesGenerator.c
static int seriesNumber = 100; // default seed value
void seriesStart( int seed ) {
seriesNumber = seed;
}
int series( void ) {
return series++;
}
To use these functions, we would need to include a header file with function prototypes for it, as follows:
// seriesGenerator.h
void seriesStart( int seed );
int series( void );
We would create the seriesGenerator.c and seriesGenerator...