Deutsch   English   Français   Italiano  
<veeqhi$ar0c$2@dont-email.me>

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

Path: ...!feeds.phibee-telecom.net!2.eu.feeder.erje.net!feeder.erje.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 18:43:14 -0300
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <veeqhi$ar0c$2@dont-email.me>
References: <veb5fi$3ll7j$1@dont-email.me> <vedv0a$5m19$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 12 Oct 2024 23:43:14 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4feb9fbad94dd6bf1d324a6d2602a358";
	logging-data="355340"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18rJi9qvhgAJDDwfUrkLZUoMgf6vs696Dg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:gSxKi5u755zzNW1wsg+IfBm04/U=
Content-Language: en-GB
In-Reply-To: <vedv0a$5m19$1@dont-email.me>
Bytes: 1910

Em 10/12/2024 10:53 AM, Bart escreveu:
> 
> It depends on what constexpr means.

It means the initialization expression must be evaluated at compilation.
Also the declarator can be used in another expression as constant.

Sample
constexpr int a = 1;
constexpr int b = a+1;

But the expression is always something the compiler need to check if is 
constant or not.

So, what I suggest is if the init expression is a constant expression 
(something we know at compile time) then the declarator is real 
constexpr (no need for a new keyword)

For instance:

const int a = 1;
const int b = a+1;


Even if not constant, the compiler can do at compile time.
for instance.
int a = 1+2;
So this has to be done anyway.
The only difference is that using 'a' cannot be used as constant in 
another expression.