How to declare then defind a const variable which can only be seen in a single source file?
The title may be somehow long, I'll explain that.
Normally, if we define a const variable, such as
const int i = 3;
its visibility will be restricted in its source file.
Now if we want to first declare, then define this variable, code becomes:
extern const int i;
const int i = 3;
But in this way, the variable i is exposed to the whole program(esp. to the linker).
Is there any way to first declare, then define a const variable which can only be seen a single source file?
Note1. Why do I want to first declare, then define, but not just at the same time?
Declare a lot of variables in a large source file may facilitate the code viewer, since they don't have to look through the file to find all the locations of definitions to see what variable is used in this file.
Note2. Why do I want to restrict this variable in the single source file?
Because I don't want the variable conflict with other source files.
Note3. This problem may apply well to non-const variables, since we can't use extern and static together.
Note4. It may be more tricky than practical, I admit...