Liste des Groupes | Revenir à cl c |
On 19/10/2024 21:41, Thiago Adams wrote:I've seen endless exampples where people inadvertently created VLAs, and where they are likely to less efficient.Em 10/19/2024 1:03 PM, David Brown escreveu:My point was that if there is no practical difference, then there is no reason to object to the VLA.On 19/10/2024 17:18, Thiago Adams wrote:>Em 10/18/2024 8:54 PM, Keith Thompson escreveu:>Thiago Adams <thiago.adams@gmail.com> writes:>I think constexpr keyword is unnecessary.>
Sure, most language features are strictly unnecessary.
>Anything you do with it could/should be done with const.>
No, absolutely not.
>
If not, do you have a sample where, using "const" as "constexpr", would create problems?
>
The sample I know is VLA.
>
const int c = 2;
int a[c]; //a is VLA because c is not a constant expression.
>
>
But this is not enough to convince me because it is better not to be a VLA here.
>
What practical difference would it make?
I don't see any practical difference. In theory, the generated code could be different, but I'm arguing that this doesn't really matter and, consequently, it's not a good reason to differentiate between const and constexpr.
>
You can't use this as a reason for arguing that it would have been better for "const" in C to gain the features that are now in C23 "constexpr", because this use of "const" was already allowed in C99. So the "const" vs "constexpr" discussion is an orthogonal issue - I was asking specifically about your comment regarding your apparent dislike of VLA's.The advantage of constexpr AIUI is that a non-constant initialiser for n is not allowed.
Les messages affichés proviennent d'usenet.