🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.netbsd.tech.kern
Article #56

Re: Do all -current compilers support C23 typed enum syntax?

#56
From: Mouse
Date: Fri, 04 Dec 2026 16:43
38 lines
3344 bytes
> However, it looks like sometime in the last couple years Apple has also deci$

I think this is an EXTREMELY bad idea, at least for C.

The whole point of such a default: case, especially when its body is a
panic, abort, or the like, is to catch cases where something has gotten
corrupted.  Declaring the enum closed (to use the terminology of the
cited #defines, assuming closed means "no other values ever") does not
affect that.  Even if the compiler generates checking code to prevent
assigning an invalid value to an object or member of such an enum type,
nothing prevents things such as wild pointer stores, or reading
corrupted data from a file or network connection or the like, from
creating invalid values, and such defaults: cases are extremely
valuable firewalls to catch such things as early as feasible rather
than letting the damage cascade.

I routinely add "default: abort(); break;" or the like to my switches,
and they have caught corruption of various sorts far too often for me
to give them up, whether by not writing them or by a compiler
arrogating to itself the decision to delete them.

The only case where such an "optimization" is actually justified in my
opinion is where every possible value of the underlying storage unit
*is* taken by the enum, such as a 256-member enum having no explicit
values declared with unsigned char as its underlying type on a machine
with 8-bit unsigned chars.  While such cases doubtless exist, I
consider them rare enough that I would still describe such a
transformation of the code as broken, possibly unless specifically
requested by pragma, non-default compiler flag, or the like.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse@rodents-montreal.org
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <202612041643.LAA00790@Stone.Rodents-Montreal.ORG>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
References: <7775F45E-DD07-404B-86FD-59C4A5CFCDA6@eschatologist.net> <>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: Mouse <mouse@Rodents-Montreal.ORG>
Newsgroups: muc.lists.netbsd.tech.kern
Subject: Re: Do all -current compilers support C23 typed enum syntax?
Date: Fri, 4 Dec 2026 11:43:06 -0500 (EST)
Organization: Newsgate at muc.de e.V.
Sender: tech-kern-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <202612041643.LAA00790@Stone.Rodents-Montreal.ORG>
References: <7775F45E-DD07-404B-86FD-59C4A5CFCDA6@eschatologist.net> <>
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="84426"; mail-complaints-to="news-admin@muc.de"
X-Erik-Conspiracy: There is no Conspiracy - and if there were I wouldn't be part of it anyway.
X-Message-Flag: Microsoft: the company who gave us the botnet zombies.
X-Composition-Start-Date: Fri, 4 Dec 2026 11:29:38 -0500 (EST)
In-Reply-To: <7775F45E-DD07-404B-86FD-59C4A5CFCDA6@eschatologist.net>
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes