Usually you want to declare a variable in only one place, preferably in a
code module. Then put an "extern" variable declaration in a header. That
way variable is allocated only once and connected together in linking stage.
If you have plain "int i;" in a header file, each source code module that
includes that header, will initialize a global variable with name i. This
can fail in compile time for multiple copies of symbol i.
Usually you want to declare a variable in only one place, preferably in a
code module. Then put an "extern" variable declaration in a header. That
way variable is allocated only once and connected together in linking stage.
If you have plain "int i;" in a header file, each source code module that
includes that header, will initialize a global variable with name i. This
can fail in compile time for multiple copies of symbol i.