🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #655

Re: Taming The Switch-Statement

#655
From: bart
Date: Wed, 21 Oct 2026 18:04
70 lines
3922 bytes
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.


Technical Details
Message-ID: <11baur1$63id$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-mail
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> <11baot1$3j98$1@dont-email.me> <aw6CS.179415$PnNb.56673@fx12.iad>

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 19:04:16 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <11baur1$63id$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> <11baot1$3j98$1@dont-email.me>
 <aw6CS.179415$PnNb.56673@fx12.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 21 Oct 2026 18:04:18 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="200269"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19HahZ5Ig/LDpif5opKbpf/"; posting-host="c65e78a22dc81d6f5c20317bcf66a407"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:SzbgSFMkRqy1WPDgAWi30xNxe14= sha256:+bTXlBecJima323TpFlNNJjgnf5HtaEL4tdnQwc7r7c=
	sha1:6sfMO5wpdyWz4bJrtycqA1LmM7Q= sha256:qC6KkC5SX+HfnRNFjQhezFJgXqJUN7HqU74Cx80erP8=
In-Reply-To: <aw6CS.179415$PnNb.56673@fx12.iad>
Content-Language: en-GB