Well C and C++ have some different rules regarding this: Linxutopia - Thinking in C++ - 3: The C in C++ - Linkage. And in C++ there is a whole other feature, extern "C" that you are not using as well, just to make a note of it.
I created an example for you. Typically external linkage works like this, especially if you want the same global constant to be referenced around the program. The only way the linker will be able to resolve all of the references to the same variable is if there is a note about external linkage when the variable is actually defined. Where it is otherwise used, an extern declaration is fine.
foo.h contains:
Code:
#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED
extern const int my_const;
void foo();
#endif
file1.cpp contains:
Code:
#include <stdio.h>
#include "foo.h"
const int my_const = 7;
int main()
{
printf("hello %d\n", my_const);
foo();
return 0;
}
file2.cpp contains:
Code:
#include <stdio.h>
#include "foo.h"
void foo()
{
printf("from foo(), %d\n", my_const);
}
And with this you can clearly tell we are referencing the same constant, defined in file1.cpp. It could also be defined in file2.cpp if that makes more logical sense, there is no technical difference.
static, as it relates to the topic, refers to static linkage.