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 9:24 PM, Thor Lancelot Simon <tls%panix.com@localhost> wrote:
>
> On Thu, Dec 03, 2026 at 08:31:18PM -0800, Chris Hanson wrote:
>>
>> In general, this is not a fruitful line of discussion: Compilers do exist to serve their users, but those users have many different and competing needs, and optimization for both speed and size are among them. And the language specification is ultimately what defines ???broken??? when it comes to how to best meet those needs.
>
> I have been avoiding so far in this conversation noting that really, this
> all stems from Apple buying itself a 50 gallon drum of trouble by just begging
> for UB by using "enum" in ABI elements, but, this seems like the time to say
> it.
You were right to avoid it, because I don’t think saying this advances the conversation at all. It presumes the people designing and implementing APIs and maintaining ABI compatibility at NeXT and Apple did not or do not know what they’re doing. To recount a little more history: NeXT and Apple *didn’t* originally use enum types directly in API precisely because of the problems they present for ABI stability in their C89 and C99 form. Instead, they followed the “anonymous enum plus typedef of int” model.
To switch to using enum types directly in API after pursuing language features that make it safe to do so were explicit choices on Apple’s part. Those choices were driven by demand for better warnings & errors, better code completion, and a better symbolic debugging experience.
My suspicion is that the optimization risk Taylor pointed out was avoided because the pervasive use of enum in C to describe *both* mutually-exclusive values *and* mixable values (flags) effectively required the compiler to treat an enum-typed variable whose members were being switched on as open-coded, and thus behave like Mouse would expect (not eliding the default clause in a switch construct). So the compiler could warn about cases not covered, but not further optimize in the face of all cases being covered without additional information.
> You have to understand the limitations of the language you're working in --
> or, if you have a polyglot ecosystem, the languages. Using enum in a binary
> interface to other people's code bespeaks profound misunderstanding of the
> limitations of C and papering over it afterwards is bound to be fraught.
Yes, you have to understand the language or languages you’re working in. Fortunately the people working on Apple’s compilers, and whoever proposed the original feature for Standard C++ (where it came from originally) did understand the languages quite well.
They ensured that using an enum type in code requiring ABI stability is perfectly fine, if one does so using the language features created specifically to enable that.
-- Chris
Home |
Main Index |
Thread Index |
Old Index