What's the difference between declaring a variable like constexpr const and constexpr?

1

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;
    
asked by anonymous 29.09.2018 / 20:39

1 answer

1

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;
    
30.09.2018 / 02:09