| Deutsch English Français Italiano |
|
<87plnvpgb9.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: constexpr keyword is unnecessary
Date: Sat, 19 Oct 2024 21:08:10 -0700
Organization: None to speak of
Lines: 35
Message-ID: <87plnvpgb9.fsf@nosuchdomain.example.com>
References: <veb5fi$3ll7j$1@dont-email.me>
<877ca5q84u.fsf@nosuchdomain.example.com>
<vf0ijd$3u54q$1@dont-email.me> <vf0l98$3un4n$1@dont-email.me>
<vf1216$p0c$1@dont-email.me> <87y12jpxvl.fsf@nosuchdomain.example.com>
<vf1d2o$2hjk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 20 Oct 2024 06:08:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cc5061371ac78e01141ee4e1be7cb736";
logging-data="293103"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gkYPWyYboegQ4V3z8MIdM"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:vgdC/4XOgg9VaWSbpJsRPfKXQH8=
sha1:JB4wovMecnRSabLCtw6R/5ouw4A=
Bytes: 2647
Thiago Adams <thiago.adams@gmail.com> writes:
> Em 10/19/2024 6:48 PM, Keith Thompson escreveu:
[...]
>> My 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.
But the new keyword already exists, and will be part of the language for
years. Removing the constexpr keyword will not be possible, because
doing so would break existing code.
> For instance, in file scope,
>
> 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.
As of C23, you're right. But what if a future C standard allows
non-constant initializers for file-scope object (as C++ already does)?
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */