Path: csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Thu, 23 May 2024 13:37:19 -0700 Organization: None to speak of Lines: 44 Message-ID: <87ttio464g.fsf@nosuchdomain.example.com> References: <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com> <87msoh5uh6.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 23 May 2024 22:37:24 +0200 (CEST) Injection-Info: dont-email.me; posting-host="04393c0e0d87ab29eec6bf33d59d4ed3"; logging-data="2031052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gjYvHtRxxqp24a7wwsBEM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:fjMFUYf4IF5vyI50Wt1Pbn1RwHE= sha1:9LqI1qeP56vk0jk67xFvZGRjjDk= Xref: csiph.com comp.lang.c:384918 David Brown writes: > On 23/05/2024 00:53, Keith Thompson wrote: [...] >> I dislike the C++ hack of making N a constant expression given >> `const int N = 42;`; constexpr made that unnecessary. > > I find that "hack" convenient at times. But I see what you mean that > it is a "hack", and I agree that "constexpr" makes such a hack > unnecessary. (Ideally, the languages would have used terms such as > "read_only" and "constant" rather than "const" and "constexpr", but > that boat sailed long ago.) > >> C23 makes the >> same (IMHO) mistake. > > I don't think so - as far as I can see, it avoids that mistake (if you > feel the "hack" was a mistake). C23 can't fix the choice of names - > that was from C90. Apparently I was mistaken. I had thought that C23 made this legal (as it is in C++): #include int main(void) { const int n = 42; switch (n) case n: puts("ok"); } There was a proposal to do this: https://thephd.dev/_vendor/future_cxx/papers/C%20-%20Initialized%20const%20Integer%20Declarations.html and I wrote a response to it: https://github.com/Keith-S-Thompson/const-proposal-response but the proposed wording does not appear in N3220. (If you want n to be a constant expression, replace "const" with "constexpr" -- or use a macro or the enum hack if you don't have a C23 compiler.) We're definitely stuck with the "const" and "constexpr" keywords, but at least the semantics of "const" are reasonably consistent. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */