Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Thiago Adams Newsgroups: comp.lang.c Subject: Re: constexpr keyword is unnecessary Date: Tue, 15 Oct 2024 10:11:48 -0300 Organization: A noiseless patient Spider Lines: 61 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 15 Oct 2024 15:11:49 +0200 (CEST) Injection-Info: dont-email.me; posting-host="77a1174b06f1d1508764a1a6759a5811"; logging-data="1801347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Re0YJx+rpD5ZCuxeZzhNey7HMUO+dH7o=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:2yX1IU9rYLhK4zcZAJTVOL6KxXc= Content-Language: en-US In-Reply-To: Bytes: 3814 On 15/10/2024 10:01, Bart wrote: > On 15/10/2024 12:41, Bonita Montero wrote: >> Am 15.10.2024 um 05:30 schrieb DFS: >>> On 10/13/2024 6:51 AM, Bonita Montero wrote: >>>> Am 12.10.2024 um 23:37 schrieb Thiago Adams: >>>> >>>>> If you are afraid your constant is not constant expression put a >>>>> static_assert. Then remove. >>>> >>>> This is unnecessary work if you have constexpr. >>>> >>>>> (C++ is a TOTAL mess. const in C++ already could be used n constant >>>>> expression) >>>> >>>> C++ is five to ten times less work for the same problem. >>> >>> >>> How do you measure "work'? >> >> In lines of code. Imagine you would specialize a container like >> unordered_map by hand in C. That would be days of work. In C++ >> it's one line of code and you get nearly optimal performance. >> Or just think about what an emplace_back on a vector of strings >> all does; if the capacity isn't sufficient a doubled vector is >> allocated (libstdc++, libc++), all objects are moved there and >> a new item is emplaced at the end. That's one line of code, but >> in C that's a half day's work. >> > > > Sure, because every time you start a new C app, you're starting from zero. > > There are no existing libraries to use. No online examples to use as > templates. There are no examples of hashtables or growable arrays that > you've implemented over decades of your own work to draw from. > > There is NOTHING. > > In reality it isn't like that. > > Use of C++ does have the advantage when posting bits of code in on-line > forums, since there are a much larger number of /standard/ libraries > that someone running your code will have access to in their > installation, if the code fragment happens to use them. > > Posted C code using a non-standard library would be problematical. > That's probably why C code that use a hash-map, for example, may need to > come with its implementation so it may appear to have a higher line count. > I think C could be improved a lot with something like ChatGPT to create parametrized containers. I was planing to create something (not as advanced of course) but something I could just write "create a vector of int" "create map of strings to int" , "create single linked list" etc.