Article View: muc.lists.netbsd.tech.kern
Article #42Re: Do all -current compilers support C23 typed enum syntax?
From: Chris Hanson
Date: Fri, 04 Dec 2026 00:27
Date: Fri, 04 Dec 2026 00:27
49 lines
4128 bytes
4128 bytes
On Dec 3, 2026, at 3:57 PM, Greg Troxel <gdt@lexort.com> wrote:
> All in all, this feels like too much complexity imposed on everyone to
> solve a perhaps-theoretical safety problem.
It’s not a theoretical problem, it’s just one that you may not have run into.
We needed this at Apple because we used enum extensively in APIs, we required ABI stability even in the face of developers needing to pass options like -fshort-enums (to port code from other platforms without extensive and invasive modification), and we got lots of negative feedback from developers on both the compiler’s lack of checks for assigning incorrect enum values and on the debugging experience with enum values.
Explicitly-typed enums are strictly an improvement, and at some point it will be safe to use them in APIs; I was really just wondering whether now was that point.
I can always just use a macro like this to handle both situations:
#if /* the compiler supports explicitly-typed enums */
#define MY_ENUM(t,n) enum n : t; enum n : t
#else
#define MY_ENUM(t,n) t n; enum
#endif
This was our solution at Apple; if the compiler supports the feature use it, if the compiler doesn’t support it just do things the old-fashioned way with an int and anonymous enum. The declaration sites then look like this:
typedef MY_ENUM(int,my_option_t) {
some_option_a = 1,
some_option_b = 2,
};
which isn’t all that messy and reads more like a usual typedef.
It sounds like this is the approach I should take in what I’m hacking on in order to enable compilation in older language modes.
-- 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:
<E96899EE-8E1A-4073-9313-F066891CB374@eschatologist.net>Path:
mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailReferences:
<rmitsktlxxw.fsf@s1.lexort.com> <>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!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 16:27:43 -0800 Organization: Newsgate at muc.de e.V. Sender: tech-kern-owner@NetBSD.org Approved: news-admin@muc.de Distribution: world Message-ID: <E96899EE-8E1A-4073-9313-F066891CB374@eschatologist.net> References: <rmitsktlxxw.fsf@s1.lexort.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="13973"; 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-Ski-Army: 25918bf334c4b7fa_1796344074629_538696005 X-MC-Loop-Signature: 1796344074628:1386984794 X-MC-Ingress-Time: 1796344074628 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eschatologist.net; s=dreamhost; t=1796344074; bh=R6hulMQghsU+GxmiJrTmhn1w0Ez5xWniU+wGderbSoE=; h=Content-Type:Subject:From:Date:Cc:Content-Transfer-Encoding:To; b=qgv0dSrrzrPc1bncgyRQ3BeJvgnrrTujJCAs+GkOY9Rl2xJYzxMGQcC0uxO4XZAtY Wrt5/OHiqx8BmnoGSWHltDxXyDDNIG5M/mc/bQKXZ5oi/Wn1+wX/j/kJ1p2+6J3C2p 7bTImMpbPKcbSVypUdjes+UXrkAsV+6E6ESpuCTXoCHDcDrPE4HV4qJAcjGgDX5Lex z4Nh3luWebzDNQzB5HKzJNPf0APKgsrTbx6/33Wdk1SDQcNWLK8m1QJb2cDRnQRo7W ptyCsAQh49MMj2FSxAzoz6KowQjs4Xyjot8wd3Fspr8EP8rWjOunEPaIgOxi88PoSs CB+Q+B/g2DhMQ== In-Reply-To: <rmitsktlxxw.fsf@s1.lexort.com> Precedence: bulk X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes