News for hackers. Stuff that matters.
Re:Sshole by zbentley on Thursday November 05, 2026 @12:26PM (#50381800)
Specifically, that the lack of tagged unions (or really, structured return types in general; you can pretend those are a tagged union if you believe hard enough) in C library interop conventions is a terrible foundation on which to build widely-used APIs.

And that just ends up indicting the C language itself. Can't send errors down a separate channel; folks might not inspect errno. Can't return NULL on error, folks might compare it blindly to another result. No tagged unions, so can't return one. Can't crash on error because there's no scoped error handling. Can't return a struct for checking .error/.result separately, because alignment and equality (and tearing and accidental clobbering and more) make that brittle as hell for widely-used APIs.

C is not a good language for library APIs. Like, really not. It has its uses/strengths, sure, but without even getting into the typical gripes people have about C, libraries--one of the things that it is used for the most--are one of the things for which it is the least well-suited.

"But it has a stable ABI!" So does a land mine. Until you touch it.

Re:Sshole by cozzyd on Thursday November 05, 2026 @03:22PM (#50383973)
you can return a struct just fine... most API's don't though.
Re:Sshole by cowlevel on Friday November 06, 2026 @12:09AM (#50388453)
Historically it didn't work well between different compilers. Maybe it still doesn't.
Re:Sshole by chuckadams on Friday November 06, 2026 @09:35AM (#50392793)
Passing and returning structs by value has been part of C since C89. Most compilers pass small structs in individual registers, and nowadays with LTO they'll even elide the copy of bigger ones if they can. What's definitely the case though is that by-value structs weren't a common thing when most of the Unix API was written.
Re:Sshole by kps on Friday November 06, 2026 @10:49AM (#50393843)
Structure assignment, passing, and returning were added in UNIX V7 C.