1

Let's say I have an application that has some default values.

Is there any significant difference between:

const int MEANING_OF_LIFE = 42;

and:

constexpr int MEANING_OF_LIFE = 42;

?

I understand that constexpr value can be used as parameters in constexpr functions, but what is if I only assign these values to some variables?

UPDATE:

This question is different from Difference between `constexpr` and `const` because it talks about a specific context of constexpr usage and requires a specific answer.

Community
  • 1
  • 1
Alex
  • 9,891
  • 11
  • 53
  • 87
  • In your "particular" snippet. They are both *core constant expressions*. However you want to prefer the `constexpr` version because it provides more guarantees should you change later decide to change the initializer to some runtime value. – WhiZTiM May 11 '17 at 12:00
  • "Is there any significant difference between ?" No. Chances are most modern compilers will generate the exact same instructions for those two lines of code. – George May 11 '17 at 12:07

0 Answers0