Without `static`, compiler exports a symbol.
$ cat value.c
int value = 42;
int get_value() {
return value;
}
$ make value.o
gcc -c -o value.o value.c
$ nm value.o
0000000000000000 T get_value
U _GLOBAL_OFFSET_TABLE_
0000000000000000 D value
This symbol, not being `const` can be modified by any other compilation unit.
$ cat main.c
#include <stdio.h>
int value;
int get_value();
int main() {
value = 123456789;
printf("%d\n", get_value());
}
$ make main.o
gcc -c -o main.o main.c
$ cc value.o main.o
$ ./a.out
123456789
Compiler when generating an object file has to assume the value of exported non-const symbol can change. It's necessary to tell the compiler that the value cannot change, either by not exporting the symbol by using `static` or making the value of it `const`. In example provided in your article `static` makes sense (or even `static const`) as I don't think there is a reason to export this global.