Deutsch English Français Italiano |
<87msoh5uh6.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: C23 thoughts and opinions Date: Wed, 22 May 2024 15:53:41 -0700 Organization: None to speak of Lines: 54 Message-ID: <87msoh5uh6.fsf@nosuchdomain.example.com> References: <v2l828$18v7f$1@dont-email.me> <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com> <v2lji1$1bbcp$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 23 May 2024 00:53:45 +0200 (CEST) Injection-Info: dont-email.me; posting-host="04393c0e0d87ab29eec6bf33d59d4ed3"; logging-data="1475313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VlE9f78aNlRAUCzEG9XII" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:aKOIY7KJzQB/P7Phy2WnxuaLZe8= sha1:xA6LXMBwTpyfn4QvWNCtsg8RWQU= Bytes: 2939 David Brown <david.brown@hesbynett.no> writes: > On 22/05/2024 19:42, Thiago Adams wrote: [...] >> - nullptr > > I am fond of nullptr in C++, and will use it in C. Like most of the > C23 changes, it's not a big issue - after all, you get a lot of the > same effect with "#define nullptr (void*)(0)" or similar. But it > means your code has a visual distinction between the integer 0 and a > null pointer, and also lets the compiler or other static checking > system check better than using NULL would. (And I don't like NULL - I > dislike all-caps identifiers in general.) Quibble: That should be #define nullptr ((void*)0) For example, this doesn't produce a syntax error for `sizeof nullptr`. Better: #if __STDC_VERSION__ < 202311L #define nullptr ((void*)0) #endif C23's nullptr is of type nullptr_t, not void*. But you'd probably have to go out of your way for that to be an issue (e.g., using nullptr in a generic selection). [...] >> - constexpr > > I will definitely use that. Sometimes I want a constant expression > for things like array sizes or static initialisers, and want to > calculate it. constexpr gives you that without having to resort to > macros. (I'd perhaps be even happier if I could just use const, as I > can in C++.) But const doesn't mean constant. It means read-only. `const int r = rand();` is perfectly valid. I dislike the C++ hack of making N a constant expression given `const int N = 42;`; constexpr made that unnecessary. C23 makes the same (IMHO) mistake. If I had a time machine, I'd spell "const" as "readonly" and make "const" mean what "constexpr" now means (evaluated at compile time). [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */