Article View: comp.lang.c
Article #656Re: Taming The Switch-Statement
From: Dan Cross
Date: Wed, 21 Oct 2026 18:38
Date: Wed, 21 Oct 2026 18:38
76 lines
3796 bytes
3796 bytes
In article <11baur1$63id$1@dont-email.me>, bart <bc@freeuk.com> wrote: >On 21/10/2026 18:21, Scott Lurndal wrote: >> bart <bc@freeuk.com> writes: >>> On 21/10/2026 16:37, Dan Cross wrote: >> >>>> 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 >>> >>> You still don't get what an ABI is. >> >> Please, enlighten us. Be specific. What exactly >> does the term ABI mean to you? > >It's what I have to deal with in a compiler back-end if I want to >support an FFI in a language. > >It's not the same problem as using that FFI to write a set of bindings >corresponding with a particular API. > >The latter problem needs to be solved even if there was no back-end and >no ABI to deal with (eg. transpiling to another language, or lowering to >some VM). > >I don't why I'm bothering, since somebody will find another stick to >beat me over the head with or to somehow try to catch me out, but here >is an example of a function inside MSVCRT.DLL.. > >In the C API (ie. stdio.h) it will be expressed like this: > > int puts(const char*); > >In my FFI and in my syntax, it is expressed like this: > > func puts (ichar)i32 > >So, this is 'creating a binding'. This can be done manually for this >one-off example. It's not perfect: on my platform, the C parameter has >'ref i8' type, but mine is more like 'ref u8'. > >At this point, the ABI doesn't come into it. > >That becomes relevant within the backend for a particular target and >platform. > >So for this call: > > puts(s) > >the ABI for x64 running Windows will tell me that 's' must be passed in >rcx, the stack needs a shadow space, it needs to be 16-byte aligned, and >the 32-bit result is placed in eax. > >For ARM64 running Linux (SYS V), then 's' is passed in x0, and the >result placed in w0. The stack will always properly aligned. > >The only overlap in API/ABI may be to do with details of how structs may >be laid out in memory. But generally, C APIs will just follow the C >rules; I don't consider it an ABI thing. It would be something to deal >with even if no ABI existed and no native code was generated. > >For my purposes, ABI is about calling conventions. ABI references may >cover a lot more (eg. for SYS V which likes to make everything as >complicated as possible). > >So, now tell me what I've got wrong. Wow. You really, truly, have no idea how any of this works. I don't even know where to begin. You just throw around words but have no idea what they mean in context. It's breathtaking, really. - Dan C.
Technical Details
Message-ID:
<11bb0rn$nbe$1@reader2.panix.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11baot1$3j98$1@dont-email.me> <aw6CS.179415$PnNb.56673@fx12.iad> <11baur1$63id$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Wed, 21 Oct 2026 18:38:47 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11bb0rn$nbe$1@reader2.panix.com> References: <119qf6l$2rmg3$1@dont-email.me> <11baot1$3j98$1@dont-email.me> <aw6CS.179415$PnNb.56673@fx12.iad> <11baur1$63id$1@dont-email.me> Injection-Date: Wed, 21 Oct 2026 18:38:47 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="23918"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross)