Deutsch   English   Français   Italiano  
<20240523095110.449@kylheku.com>

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

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: C23 thoughts and opinions
Date: Thu, 23 May 2024 20:23:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20240523095110.449@kylheku.com>
References: <v2l828$18v7f$1@dont-email.me>
 <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com>
 <v2lji1$1bbcp$1@dont-email.me> <20240523154331.000063da@yahoo.com>
 <v2ngf7$1p3o2$2@dont-email.me>
Injection-Date: Thu, 23 May 2024 22:23:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6aa71b7ebec593e21606490f7fbb0158";
	logging-data="2026723"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/LEjzWrPiXscPRZt/bB/anY0ls2QcOYAs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:oYZksRtzJymPJkGMoomkNy37IEc=
Bytes: 2167

On 2024-05-23, David Brown <david.brown@hesbynett.no> wrote:
> So yes, I /could/ use enum constants for things that are not 
> enumerations.  I /did/ use them for that.  But going forward with C23, 
> I'll use constexpr instead.

The value of an enum is:

1. Compiler warns of incomplete switch cases.

2. In a debugger when you examine an enum-valued expression or
   variable, you get the symbolic name:

3. Safety (with C++ enum rules: no implicit
   conversion from ordinary integer type to enum).

Historically, C code bases have abused enums to defined constants
like "enum { bufsize = 1024 }" for understandable reasons, but it is a
cringe-inducing hack, which is also incomplete and inflexible; e.g. what
if we want a floating-point constant.

I've benefited from (3) in C programs that were contrived
to be compilable as C++. (That practice, though, tends to increasingly
hamper your dialect choice though, as the languages diverge and make
only small steps here and there to become closer.)

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca