The static const int myConstant = 1 sample that appears in the header files is a bit strange because the static limits the scope of a variable to a specific translation unit. Therefore, this variable may not be available from other translation units. Therefore, I do not understand why someone can set a variable in the header file, although this variable can never be addressed externally.
Note that if different translation units include a header, then each translation unit will define its own, somewhat "private" instance of this variable.
I think the general template should be:
In the header file:
extern const int myConstant;
In one implementation file of the entire program:
const int myConstant = 1;
The comments say, however, that this will prevent the compiler from being optimized, since the constant value is not known at the time the translation unit is compiled (and that sounds reasonable).
So, it seems that the "global / general" constants are impossible and that a situation with the somewhat conflicting keyword static may occur in the header file.
Also, I would use constexr to specify a compile-time constant (although the compiler could still get it):
static constexpr int x = 1;
Since the static still bothers me, I did some research and experimentation on constexpr without the static , but with the extern keyword. Unfortunately, extern constexpr still requires initialization (which makes it a definition then and leads to duplication of character errors). Interestingly, at least with my compiler, I can actually define constexpr int x = 1 in different translation units without introducing a compiler / linker error. But I did not find support for this behavior in the standard. But the definition of constexpr int x = 1 in the header file is even more curious than static constexpr int x = 1 .
So - a lot of words, few conclusions. I think static constexpr int x = 1 is the best choice.