Deutsch English Français Italiano |
<v2pl5g$28ola$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Fri, 24 May 2024 11:03:43 +0200 Organization: A noiseless patient Spider Lines: 52 Message-ID: <v2pl5g$28ola$1@dont-email.me> References: <v2l828$18v7f$1@dont-email.me> <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com> <v2lji1$1bbcp$1@dont-email.me> <9be0c55c-38f8-496c-b335-84ad281e1753@gmail.com> <v2nc5h$1oban$1@dont-email.me> <c5866b5a-0314-4e70-af56-a86b63986b0c@gmail.com> <v2nfai$1ougd$1@dont-email.me> <cf267279-e9cf-415f-898c-f5830a997529@gmail.com> <87ed9s42sb.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 24 May 2024 11:03:44 +0200 (CEST) Injection-Info: dont-email.me; posting-host="aa31083d92649562fe347cd52a2a5ec5"; logging-data="2384554"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19x9bFuR2ZeerD05GSQFWU9sz2ozSSYvr4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:9DjaoKb8f0zW2SfSadt9D1gTsog= Content-Language: en-GB In-Reply-To: <87ed9s42sb.fsf@nosuchdomain.example.com> Bytes: 3554 On 23/05/2024 23:49, Keith Thompson wrote: > Thiago Adams <thiago.adams@gmail.com> writes: >> On 23/05/2024 10:11, David Brown wrote: >>> On 23/05/2024 14:38, Thiago Adams wrote: > [...] >>>> I already see bad usages of constexpr in C++ code. It was used in >>>> cases where we know for sure that is NOT compile time. This just >>>> make review harder "why did someone put this here?" conclusion was >>>> it was totally unnecessary and ignored by the compiler. The >>>> programmer was trying to add something extra, like "magic" hoping >>>> for something that would never happen. >>>> >>> IME poor or confusing uses of "constexpr" are for functions, not >>> objects, and C23 does not support "constexpr" for functions. >> >> The sample C++ was something like >> >> constexpr char * s[] = {"a", "b"}; >> for (int i = 0; i < sizeof(s); i++) >> { >> //using s[i] >> } >> >> I checked in C, it is an error. > > Apparently C23 has stricter rules for constexpr than C++ does. I can > imagine those rules being relaxed in future editions of the C standard. > From the proposal for "constexpr" in C23, <https://open-std.org/JTC1/SC22/WG14/www/docs/n3018.htm>, it says: """ There are some restrictions on the type of an object that can be declared with constexpr storage duration. There is a limited number of constructs that are not allowed: pointer types: allowing these to use non-trivial addresses would delay the deduction of the concrete value from translation to link-time. For most of the use cases, such a feature can already be coded by using a static and const qualified pointer object, we don’t need constexpr for that. Therefore we only allow pointer types if the initializer value is null. """ I'm not sure (and haven't looked at all the discussions involved, so I could be completely wrong), but I think there is concern that constexpr pointers, other than null pointers, might need more features in the linker than C currently requires. C++ already has more demands of linkers to handle things like inline variables and statics in templates.