Sujet : Re: C23 thoughts and opinions
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 23. May 2024, 14:31:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2ngf7$1p3o2$2@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 23/05/2024 14:43, Michael S wrote:
On Wed, 22 May 2024 22:11:44 +0200
David Brown <david.brown@hesbynett.no> wrote:
>
I will definitely use that. Sometimes I want a constant expression
for things like array sizes or static initialisers, and want to
calculate it. constexpr gives you that without having to resort to
macros.
I don't say that everything that can be done with C23 constexpr can be
done with enum, but for uses like ones you mentioned above, 90%
probably can be done with enum.
I realise that, and use enum for such things today. But IMHO constexpr is neater and it also covers the other 10%.
I think most of the new features of C23 neaten up the language a bit. They are not game-changers - I doubt that any of them will significantly change the way anyone writes their code (especially for those already happy with gcc or clang extensions). But there are several things here that can make code a little nicer.
So yes, I /could/ use enum constants for things that are not enumerations. I /did/ use them for that. But going forward with C23, I'll use constexpr instead.