constexpr vs. static const: Which one to prefer?
For defining compile-time constants of integral types like the following (at function and class scope), which syntax is best? static const int kMagic = 64; // (1) constexpr int kMagic = 64; // (2) (1) works also for C++98/03 compilers, instead (2) requires at least C++11. Are there any other differences between the two? Should one or the other be preferred in modern C++ code, and why? EDIT I tried this sample code with Godbolt's CE : int main() { #define USE_STATIC_CONST #ifdef USE_STATIC_CONST static const int kOk = 0; static const int kError = 1; #else constexpr int kOk = 0; constexpr int