🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#34
From: Chris Hanson
Date: Thu, 03 Dec 2026 21:54
35 lines
3983 bytes
On Dec 3, 2026, at 5:12 AM, Mouse <mouse@rodents-montreal.org> wrote:

> What benefit does this bring?  enum constants have historically been
> ints (I don't _like_ this - it feels to me like conceptual type
> confusion - but it's how they've worked), so, unless you anticipate
> wanting an argument that is smaller or larger than int, I see no value
> in attaching a specific type to it.

The problem is that without attaching a specific type, the language allows the compiler to choose the type to use to represent the enumeration, which means it can change based on things like compiler options, which in turn means the use of enum for defining types is not ABI-stable.

> Even if you do, all you need is to
> document the argument as having its actual type.

That’s exactly the point: This construct was added to C++, and then Objective-C, and then C so that an argument’s, structure member’s, or variable’s declared type can *be* the enum type while also remaining ABI-stable, which is better for both documentation and debugging.

In the example you gave of using enum, you left the enum anonymous, which means usage of the enum has to via a variable, argument, or structure member with an integer type. That means the compiler cannot provide an error or warning about using an incorrect value, and the debugging symbols generated for the function (call site or implementation) doesn’t reference the enumeration and thus won’t provide a useful symbol when stepping.

  — 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: <950F1479-FF19-4169-92AF-382193ECF93A@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: <202612031312.IAA24669@Stone.Rodents-Montreal.ORG>

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 13:54:20 -0800
Organization: Newsgate at muc.de e.V.
Sender: tech-kern-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <950F1479-FF19-4169-92AF-382193ECF93A@eschatologist.net>
References: <202612031312.IAA24669@Stone.Rodents-Montreal.ORG>
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="4777"; 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-Madly-Society: 6497c1b5703916cd_1796334871577_681292528
X-MC-Loop-Signature: 1796334871577:1463150465
X-MC-Ingress-Time: 1796334871577
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eschatologist.net;
	s=dreamhost; t=1796334871;
	bh=ddLRNeUMdKOXMAdsMDLkiisDZqf3+CX/DfVzJ0ftf6k=;
	h=Content-Type:Content-Transfer-Encoding:From:Subject:Date:Cc:To;
	b=QZRZgfxl+zHCJWGmHCR7jISbwMYFSEut6SyvaiocpU3I47d4VI6ELeB1B46+q1dVE
	 5HZU1dcvK48hqcrM2ZJ9QUgIcxZbebl2yQOG8K05zmWcpH0nNUSDNf+aLU3Bp12Llb
	 otxC925o29CK2JZPOlJy+Ncz+Oat7cUTF1pdZi7Knf3eOlyFSQRGkoOye+Gyr45YAu
	 gc23HYDAUqo18JTzrsRtK59oFCa8IOmcEWpk3xuoAmZ0ym4g1LkWdk9ekgu337BODv
	 RliY04PlrWDQPBpkNxVMHrs6dX/Pd34thbkPZumVyTdz2MY+j10X+ohQuuf9zdz9jp
	 32fs3wbM4sTgQ==
In-Reply-To: <202612031312.IAA24669@Stone.Rodents-Montreal.ORG>
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes