tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

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



On Thu, 3 Dec 2026 16:04:58 -0800
Chris Hanson <cmhanson%eschatologist.net@localhost> wrote:

> On Dec 3, 2026, at 3:48 PM, Bobby Bingham <koorogi%koorogi.info@localhost>
> wrote:
> > 
> > On Thu, 3 Dec 2026 13:54:20 -0800
> > Chris Hanson <cmhanson%eschatologist.net@localhost> wrote:
> >   
> >> 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.  
> > 
> > There are many compiler options that can change the ABI in
> > incompatible ways, ranging from completely incompatible (e.g.,
> > -m32/-m64) to more subtle differences (-m[no-]align-double,
> > -mlong-double-*, -mpreferred-stack-boundary, -msoft-float on some
> > targets, etc).
> > 
> > I don't think the solution is to try to code around these options,
> > but to say they shouldn't be used where ABI compatibility matters.  
> 
> The language committees obviously disagree, as the specific language
> feature I’m talking about was added to C++ and then Objective-C and
> finally to C specifically so language users would no longer have to
> worry about this ABI risk.

I don't personally mind the use of this feature, though I would hope
any public header would be kept compatible with older versions of C, as
I see you've already suggested.

But I see the reason for this feature's existence as roughly the
reverse of how you're suggesting using it.  I see it as allowing
developers that want something like -fshort-enums a standardized way to
get that behavior without breaking ABI with everybody else, rather than
a way for developers who are happy with the compiler-chosen backing
type to accommodate ABI-breaking compiler flags.

That said, this is just my 2 cents.  I'm new here and can't speak for
the project.

> 
> More specifically, I’d say that using anonymous enums and int in APIs
> is coding around a flaw in C’s specification of enum, and that the
> explicit typing feature eliminates the need to code around this flaw.
> 
>   — Chris
> 

--
Bobby


Home | Main Index | Thread Index | Old Index