🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#35
From: Chris Hanson
Date: Thu, 03 Dec 2026 22:12
36 lines
3747 bytes
On Dec 3, 2026, at 4:58 AM, Anders Magnusson <ragge@tethuvudet.se> wrote:
> can you explain in which situation you need to modify the type of an enum?  Since it is supposed to be (representable as) an int?

I explained briefly in another response, but without an explicit type, the type used to represent an enum is up to the compiler. It’s int by default, but doesn’t have to be, and can be changed by things like compiler arguments (to e.g. prefer the narrowest integer type, or the widest).

And if you want to actually get compiler enforcement for invalid assignments and a good debugging experience, you actually need to use the enum name (or a typedef) in structure members, variables, and arguments.

These combine to mean that

    enum call_options { a = 1, b = 2, };
    int some_call(enum call_options options);

does not get a stable ABI, but one that can change based on compiler arguments. Using “enum call_options : int” tells the compiler how to represent the type in a way that cannot be overridden. And the above is strictly superior to

    enum { a = 1, b = 2, };
    int some_call(int /* see above */ options);

because just using int and a comment doesn’t get any compiler enforcement or debugging affordances.

  — 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: <440649C8-8CC6-4695-B7A8-6FBEA32999F6@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-mail
References: <d1e2ece0-96e4-4a8b-9838-bf3dda2d8db3@tethuvudet.se>

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 14:12:24 -0800
Organization: Newsgate at muc.de e.V.
Sender: tech-kern-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <440649C8-8CC6-4695-B7A8-6FBEA32999F6@eschatologist.net>
References: <d1e2ece0-96e4-4a8b-9838-bf3dda2d8db3@tethuvudet.se>
MIME-Version: 1.0 (1.0)
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="18654"; 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-Absorbed-Hook: 45ab935262068cdb_1796335959557_436807501
X-MC-Loop-Signature: 1796335959557:957321055
X-MC-Ingress-Time: 1796335959556
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eschatologist.net;
	s=dreamhost; t=1796335955;
	bh=Q00InSrSSyc3Bq+7+IZCXeDUiEgHbxMhyaRGolhiVCM=;
	h=Content-Type:Content-Transfer-Encoding:From:Subject:Date:Cc:To;
	b=1TWUe4gYN5LgowFqMUEyPepzlMFRO4X/F9+oxBd/UDvhjDoQDjQB3fFo5TO+eVTpz
	 4HZ7MwPUMhavtlz7m0K/Sh1xe1DLXnV6903Pm3sr79RwRhnHCth94iC3AJjiEPrg9/
	 gS0vYisxF1Q8MHKsandaGbdQzQnkyt1oYbPtJDTXaHa6H+PmCruHx0OnkstXuVBjvb
	 d8jhkBR4Dtw9VHE3Wvb/8BfPtmwpJ/PDshJ2JWOlmULx0pxOZTRYO16ejSvC5SUKfV
	 SxFGaowOWsVi6IDPlBdk7Fs6nTEp/m86vFPFgD+17NCZSEwMTy5+xyeogRqfkqao7M
	 fYEpU35763FCg==
In-Reply-To: <d1e2ece0-96e4-4a8b-9838-bf3dda2d8db3@tethuvudet.se>
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes