🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#52
From: Chris Hanson
Date: Fri, 04 Dec 2026 06:33
67 lines
5378 bytes
On Dec 3, 2026, at 9:24 PM, Thor Lancelot Simon <tls@panix.com> wrote:
> 
> On Thu, Dec 03, 2026 at 08:31:18PM -0800, Chris Hanson wrote:
>> 
>> In general, this is not a fruitful line of discussion: Compilers do exist to serve their users, but those users have many different and competing needs, and optimization for both speed and size are among them. And the language specification is ultimately what defines ???broken??? when it comes to how to best meet those needs.
> 
> I have been avoiding so far in this conversation noting that really, this
> all stems from Apple buying itself a 50 gallon drum of trouble by just begging
> for UB by using "enum" in ABI elements, but, this seems like the time to say
> it.

You were right to avoid it, because I don’t think saying this advances the conversation at all. It presumes the people designing and implementing APIs and maintaining ABI compatibility at NeXT and Apple did not or do not know what they’re doing. To recount a little more history: NeXT and Apple *didn’t* originally use enum types directly in API precisely because of the problems they present for ABI stability in their C89 and C99 form. Instead, they followed the “anonymous enum plus typedef of int” model.

To switch to using enum types directly in API after pursuing language features that make it safe to do so were explicit choices on Apple’s part. Those choices were driven by demand for better warnings & errors, better code completion, and a better symbolic debugging experience.

My suspicion is that the optimization risk Taylor pointed out was avoided because the pervasive use of enum in C to describe *both* mutually-exclusive values *and* mixable values (flags) effectively required the compiler to treat an enum-typed variable whose members were being switched on as open-coded, and thus behave like Mouse would expect (not eliding the default clause in a switch construct). So the compiler could warn about cases not covered, but not further optimize in the face of all cases being covered without additional information.

> You have to understand the limitations of the language you're working in --
> or, if you have a polyglot ecosystem, the languages.  Using enum in a binary
> interface to other people's code bespeaks profound misunderstanding of the
> limitations of C and papering over it afterwards is bound to be fraught.

Yes, you have to understand the language or languages you’re working in. Fortunately the people working on Apple’s compilers, and whoever proposed the original feature for Standard C++ (where it came from originally) did understand the languages quite well.

They ensured that using an enum type in code requiring ABI stability is perfectly fine, if one does so using the language features created specifically to enable that.

  -- Chris


--
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: <C142AF44-C4BD-4852-9BA0-4F42213893A4@eschatologist.net>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!usenet.goja.nl.eu.org!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: <axJOpU_bzJC_LUSU@panix.com> <>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!usenet.goja.nl.eu.org!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: Chris Hanson <cmhanson@eschatologist.net>
Newsgroups: muc.lists.netbsd.tech.kern
Subject: Re: Do all -current compilers support C23 typed enum syntax?
Date: Thu, 3 Dec 2026 22:33:51 -0800
Organization: Newsgate at muc.de e.V.
Sender: tech-kern-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <C142AF44-C4BD-4852-9BA0-4F42213893A4@eschatologist.net>
References: <axJOpU_bzJC_LUSU@panix.com> <>
MIME-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\))
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="37645"; mail-complaints-to="news-admin@muc.de"
Authentication-Results: mail.netbsd.org (amavisd-new);
	dkim=pass (2048-bit key) header.d=eschatologist.net
X-Sender-Id: dreamhost|x-authsender|cmhanson@eschatologist.net
X-Sender-Id: dreamhost|x-authsender|cmhanson@eschatologist.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|cmhanson@eschatologist.net
X-MailChannels-Auth-Id: dreamhost
X-Stop-Language: 47d3599343995981_1796366044310_993533086
X-MC-Loop-Signature: 1796366044310:2557689925
X-MC-Ingress-Time: 1796366044310
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eschatologist.net;
	s=dreamhost; t=1796366044;
	bh=eIGkf6dDvEC1+REBjr85GV68asgFUkHVyGjYVX60AYA=;
	h=Content-Type:Subject:From:Date:Cc:Content-Transfer-Encoding:To;
	b=CiEGH614VSlA0THZhGgB0BW3eLaSXYJtUN86qGgTwNeJi3dZgpeaVjLZImgRvxS+3
	 9bWxxrncqcXolIKk59pnFlxoqh74xx7gbWSIxScCAjp8fP0ICokoaPPTOWgVVkuKVt
	 oeBUgtVbNys6xFg0/nkFWwsEptpPzi0YURnQe0KQXjuIKytZTB0tup7JlihcRDDlYF
	 Ew21Y+VBocG+SXqcx9x13NQZEdIO37yCWNA45Bd5gaP5ssmMltrbJHcPARcoTpO5nG
	 Fqo2bbpus5EChspUF+jipFL6hu3T/5nmpbjKXv0kTHtAYySWPZILR8sgAoAtYeJzRH
	 BUI8+Cu6mluWQ==
In-Reply-To: <axJOpU_bzJC_LUSU@panix.com>
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes