Liste des Groupes | Revenir à cl c |
I used to find const confusing, as it sometimes meant 'read-only' and other times 'immutable.'I'm asking myself what should be confusing with constexpr.
Now, it seems less confusing to me. When const is used with variables that can be initialized (init-declarator), it acts as 'immutable,' meaning the storage is constant.
In other contexts, like function parameters, const means 'read-only' because we don’t know if the storage is constant or not.
It’s also interesting to note that constexpr acts as a storage qualifier. What the compiler needs to know when evaluating an expression at compile time, without depending on flow analysis, is the guarantee that the object is immutable. This makes it safe to use the value it has at initialization when the initialization is also a compile time expression.
const used in variables that can be initialized gives the compiler the same guarantees.
Les messages affichés proviennent d'usenet.