Liste des Groupes | Revenir à cl c |
Thiago Adams <thiago.adams@gmail.com> writes:Yes. But const can be improved and we can just ignore constexpr.Em 10/19/2024 6:48 PM, Keith Thompson escreveu:[...]But the new keyword already exists, and will be part of the language forMy reasons for not wanting `const int c = 2;` to make c a constant>
expression have nothing to do with any theoretical difference in
generated code.
>
My reason is that "const" and "constant" are two almost entirely
distinct concepts. Conflating them makes the language more confusing.
Making the name of a "const" object a constant expression adds no new
capabilities beyone what we already have with "constexpr".
I see some differences but not enough to justify a new keyword and I
think it also generates confusion. So it is a matter of choosing what
that of confusion we want.
years. Removing the constexpr keyword will not be possible, because
doing so would break existing code.
Then it could have initialization order problem..and C does not have exceptions to report error in initialization..For instance, in file scope,As of C23, you're right. But what if a future C standard allows
>
const int a = 1;
constexpr int b =1;
>
In both cases, because it is file scope, a and b need to be
initialized with constant expressions. I don´t see anything more
special in b compared with a to make any distinction.
non-constant initializers for file-scope object (as C++ already does)?
Les messages affichés proviennent d'usenet.