🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#57
From: Andrew Cagney
Date: Fri, 04 Dec 2026 17:01
54 lines
5185 bytes
On Thu, 3 Dec 2026 at 08:12, Mouse <mouse@rodents-montreal.org> wrote:
>
> > For example:
>
> >     typedef enum : int {
> >             subsys_thing_a = 0,
> >             subways_thing_b,
> >     } subsys_thing_t;
>
> >     int subsys_call(subsys_thing_t thing);
>
> 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.  Even if you do, all you need is to
> document the argument as having its actual type.  The only real
> difference I see between
>
>         enum {
enum myenum {
>                 FOO = 1,
>                 BAR,
>                 BAZ,
>         };
>
> and
>
>         #define FOO 1
>         #define BAR 2
>         #define BAZ 3
>
> is that they obey different scope rules.  You can pass either one to an
> argument of any integral type just fine (well, possibly except _Bool).
>
> What am I missing?

(somewhat off topic; I thought GCC enums were unsigned by default)

Given:

enum myenum { MA, MB, MC, };
enum notmyenum {NB, NA, NZ, };

then given:
   myfunc(enum myenum e);
compilers can warn about the mismatch:
   myfunc(NB);
Because of the really an int/unsigned rule, it's all a bit loosy
goosy, but better than nothing.

--
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: <CAJeAr6u_J=8uFMF6ML2bgMN-eErhb8+axYGCOGyX+KqXaUzajA@mail.gmail.com>
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: <202612031312.IAA24669@Stone.Rodents-Montreal.ORG> <>

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: Andrew Cagney <andrew.cagney@gmail.com>
Newsgroups: muc.lists.netbsd.tech.kern
Subject: Re: Do all -current compilers support C23 typed enum syntax?
Date: Fri, 4 Dec 2026 12:01:11 -0500
Organization: Newsgate at muc.de e.V.
Sender: tech-kern-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <CAJeAr6u_J=8uFMF6ML2bgMN-eErhb8+axYGCOGyX+KqXaUzajA@mail.gmail.com>
References: <202612031312.IAA24669@Stone.Rodents-Montreal.ORG> <>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="97446"; mail-complaints-to="news-admin@muc.de"
Authentication-Results: mail.netbsd.org (amavisd-new);
	dkim=pass (2048-bit key) header.d=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796403684; x=1797008484; darn=netbsd.org;
        h=content-type:cc:to:subject:message-id:date:from:in-reply-to
         :references:mime-version:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=+csvU4XSIPVT7kmwo8JiZD/Y7fZ8E/o6+Yv1QiHteDI=;
        b=S2BGHSAWWG8HzhmDxicNUySjZMz04Z9i3JfSPpdWCUymvR3y+5xUxwtIb+nuKzZgl/
         3X6dMAJ9BNlrs3cP3AsliVr5Oo5qXwSJKfe3tda6PMSpmqG6u/vnY35dbNPTfimG3B6K
         X3ki2ImxQncqNYrqOrp1I7EDMQiUS/2MVWqNoPgmgu/ZntdlonQXewQyAdzIpTOprFx3
         z4BNo+in9SYpTLRhV7BPz4HvloqI/ThiiloKUD3LQTXQRk14bCXkjuA1ECx5craAR9dg
         i7CQDU04ngThM3AtwkGiKR1t7CT7AKystxanpsIgq/CnFh5wcumQxMLZleTzzpVBLbzj
         jfrg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796403684; x=1797008484;
        h=content-type:cc:to:subject:message-id:date:from:in-reply-to
         :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=+csvU4XSIPVT7kmwo8JiZD/Y7fZ8E/o6+Yv1QiHteDI=;
        b=xt2KV7Um3PaIHMrzuZH8r+Slb2xyFQyn0dFrTULkDCl5GyPNI1uzmFxznJtGXn7JLc
         PyZVpvcvNWWI6Wi5qf6jPFCY2UcyRPS5r88srwjp9djW53Ka6XW/3X+Qsx04HoloV/6H
         w5eYNu+DmoKFcpVFj1O3L7LXyypOJvLQbz2OYG1FOk/GnS5VHcgfKoNvxqKImWd6kZ7G
         /9/gX4zuFlVhkKwykofG1GPhtJF2uw7tkXkDu5iqDrmEF/IWr57pkFWaLfmNBRa8I4s4
         +uzTA2UY+6YXyEQq+R60ePYNZ8CMmGlrGrEWhm4gRskEYnYQ+1YWDpuAngDwAkwCRg08
         pS2A==
X-Gm-Message-State: APuU4Z8teiakbT5XUOfCsHAmFBpgeR0UO4CvdupBY7wTQ/wDqoNu6SjM
	ZGZ8IucRUctj1tOfhon10lxGvyGxa3+pWGCdoYYHk1yEhqRBb4hjEb80SudfeeTgyhLFemVLQEY
	nMSUNuFXUirYP1xI30ba96s9eUY2LdJYj
X-Gm-Gg: AZFdTZex62e7/9o95CYkaA7tPKDPOBAVWapMYSaHVBK7g1p1q8UTY4J0CB8YqLAi4Or
	UhNhoL86Y/euQbQWX2PrjAvz9b6TxRVwlfYtBSybvSyIugXyqqzkQ/xvHSBmd2Oa6ZqmrkRNziP
	fnQq2Eara1W4PMR93CVuR1mx/6EHF8fbFcOJzi7d6O0dJ3hV7ocWFVotrAcvwVLTTHICJYzYwU4
	lINJajymPc1t2qVZOFcxDdempkBS6u9kO42aGOhwRJCCcDGIllOjqOVyl+PsSo1v9m/7uCL0ejd
	U8QFFJv+40hUY3EAOwp5KWMAwx5JXbvlErCJemGicwHO5Lb0LhCkuNqscGG0fwaJ9+xWgBzmYX/
	y5whbTU2cTFxiHuL5f/WIGVDsQpdSy4g4fYdOqCxpX1sj5Q40CTFLdnCono9D724eLgnaYOyoyO
	walLSZ5jnvEERKib2UD+2lU97L1axNa83rESZ/yHQhQoG0uRjYU0XS/g==
In-Reply-To: <202612031312.IAA24669@Stone.Rodents-Montreal.ORG>
X-Gm-Features: Aa3M54odZ_cueUroaV5GFy-MKg9h9AeiMdckdy5mvZAw7yRWBqC4I4MKgoPqPC4
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes