Deutsch   English   Français   Italiano  
<vedt8k$64du$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: constexpr keyword is unnecessary
Date: Sat, 12 Oct 2024 10:23:32 -0300
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vedt8k$64du$1@dont-email.me>
References: <veb5fi$3ll7j$1@dont-email.me>
 <vebp8r$3ok6d$1@raubtier-asyl.eternal-september.org>
 <vebpo5$3olu3$1@dont-email.me>
 <vebtjp$3p9sm$1@raubtier-asyl.eternal-september.org>
 <vebubq$3p8oj$1@dont-email.me>
 <vecuhe$1o44$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 12 Oct 2024 15:23:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4feb9fbad94dd6bf1d324a6d2602a358";
	logging-data="201150"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19WajAlwwe2QCQlkuZCslOnMyXZ4nXo5aM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:wjtCnkBeBapqeEM2W1qaC4ozk5Q=
In-Reply-To: <vecuhe$1o44$1@raubtier-asyl.eternal-september.org>
Content-Language: en-GB
Bytes: 2305

Em 10/12/2024 1:39 AM, Bonita Montero escreveu:
> Am 11.10.2024 um 21:30 schrieb Thiago Adams:
>> Em 10/11/2024 4:17 PM, Bonita Montero escreveu:
>>> Am 11.10.2024 um 20:11 schrieb Thiago Adams:
>>>
>>>
>>>
>>>> constant expression make sense in C. It is not new, it is very old.
>>>
>>> const has a definition and it allows non compile-time evaluated
>>> variables.
>>
>> yes. but?
> 
> With constexpr you could enforce that the expression you assign is
> compile-time evaluated. That's while constexpr would make sense.

This is already the default in C  for file scope variables and places 
where constant expression are required like enums.

Let's see local variables, that may or may not have a compile time value.

For instance


int main(){
   const int a = 1;
   constexpr int i = a; //error
}

i must be initialized with a constant expressions.
What I am suggesting is

  const int a = 1; // is a constant expression
  const int i = a; // is a constant expression


Note that C++ is already like that