Article View: comp.lang.c
Article #653Re: Taming The Switch-Statement
From: bart
Date: Wed, 21 Oct 2026 16:22
Date: Wed, 21 Oct 2026 16:22
82 lines
4535 bytes
4535 bytes
On 21/10/2026 16:37, Dan Cross wrote: > In article <11baiuc$11ac$1@dont-email.me>, bart <bc@freeuk.com> wrote: >> On 21/10/2026 12:21, David Brown wrote: >>> On 21/10/2026 03:04, bart wrote: >>>> Here, one problem is that there are 3 types that I don't know and >>>> would have to look up. >>> >>> Incorrect. >> >> If I wanted to use function from a language that is not C and for which >> nobody has yet created a set of bindings, then I would have to >> investigate every single abstract type. > > That is true of every programming language. It's not clear what you mean by 'that'. But typically APIs are primarily expressed as C headers. With mainstream languages, somebody else has usually already done that work. >> Even then, I might find that a year later, 'err_t' has been defined to >> be something slightly different. Standard types are easier to deal with >> and more likely to be stable. > > That is also true of every programming language. Then it is also true that standard types will be more stable. > You can write some library in BartM or whatever language you > like, and someone might write a binding to call it from, say, > Pascal; and then a year down the road, you might change your > compiler (since I gather you don't bother with a well-defined > ABI, based on your not seeming to understand them You still don't get what an ABI is. > Welcome to programming. It's Hard(TM). Some things could be easier. Someone produces library (eg. DLL binary). That library exports a set of function names, but not a set of language-neutral function signatures. (And it will not export types, structs, enums etc needed to use the library.) Why not do that? Just a DLL having the C header API embedded within it would be a start! You don't need to source them separately, and they will always match in version. >> In general most boil down to one of i32 u32 i64 u64. > Judicious use of types can render entire categories of errors > unexpressible. Alexis King wrote a wonderful post about this, > expressed using Haskell, but the general principles apply more > broadly. If you want to use lots of abstraction then use a language with strict type systems that can back them up. Ada for example. But it's not a language I'd want to use. You can go too far down that path (look at the Frink programming language). >>> It is also nice to know that it can be used in a switch, and cast to an >>> int for printf. >> >> How would you know that? I thought it was abstract! Maybe err_t is a >> small struct. > > Because the documentation about it tells you that you can: "The > type `err_t` is used to represent errors. It can be cast to > `int`." Really, this is table-stakes software development. In this case it doesn't. It is an alias for 's8_t', which is itself an alias for 'int8_t' (which itself is probably an alias for 'signed char' within 'stdint.h'. What it does say however is that, if you define a certain macro, you can make err_t' any type you like. I don't know how that would work here; I assume it still has to be a numeric type, but it is not stated.
Technical Details
Message-ID:
<11baot1$3j98$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11b933e$3h3d0$1@dont-email.me> <11ba78m$3peq3$3@dont-email.me> <11baiuc$11ac$1@dont-email.me> <11bam77$6at$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Wed, 21 Oct 2026 17:22:57 +0100 Organization: A noiseless patient Spider Lines: 82 Message-ID: <11baot1$3j98$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11b933e$3h3d0$1@dont-email.me> <11ba78m$3peq3$3@dont-email.me> <11baiuc$11ac$1@dont-email.me> <11bam77$6at$1@reader2.panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 21 Oct 2026 16:22:58 +0000 (UTC) Injection-Info: dont-email.me; logging-data="118056"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jptYS4eKOAxymFmrZRCOH"; posting-host="c65e78a22dc81d6f5c20317bcf66a407" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:fYZ3ENPBKlgwWvZuzqxP4zz94ck= sha256:l9vigdULS9UJNroCaW9/uFoDMaEXnaHK4U7YKfinRl0= sha1:Vqu7gCXdkOpZ4ycsQtYvHddlfYA= sha256:2H3kqC8fCnwbv+MG6Ks4TrLHyc3nDAdlrl0LYotz/V0= Content-Language: en-GB In-Reply-To: <11bam77$6at$1@reader2.panix.com>