I would like to define several global constant values which will be used across multiple .cpp files. It is not essential to know the values at compile time.
One option is to define, e.g. const double some_constant =4.1;
in a header file and include it in my various .cpp files. (This seems like the most natural option, but I am a complete beginner.)
Another option is to put extern const double some_constant;
in the header file and set it as const double some_constant=4.1;
in a separate .cpp file, then include the header files as before. (I have heard that this allows the compiler to make better optimizations, but I don't understand why.)
Or, as mentioned in an answer to this post, a third possibility is to define
constexpr double some_constant {4.1};
Is there actually any difference between these options in terms of performance/allowing the compiler make the best optimizations? I am using g++ with the -O3 flag if that is relevant.