What's the difference between declaring a constant as constexpr const
to only a constexpr
?
constexpr const float max_height = 3.0f;
constexpr float max_height = 3.0f;
What's the difference between declaring a constant as constexpr const
to only a constexpr
?
constexpr const float max_height = 3.0f;
constexpr float max_height = 3.0f;
constexpr
tells the compiler that it has the result of that expression at compile time so it can optimize and resolve without taking it to execution. const
only ensures that that value will not be changed during execution.
In practice in both cases shown gives in the same because it is in fact a literal, would make a difference in an expression, a function, something that depends on some information that is not present directly there in the statement. And surely something solved in compilation can not be changed. You could even do:
const float max_height = 3.0f;