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 Dec 3, 2026, at 5:12 AM, Mouse <mouse%rodents-montreal.org@localhost> 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
Home |
Main Index |
Thread Index |
Old Index