🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #648

Re: Taming The Switch-Statement

#648
From: bart
Date: Wed, 21 Oct 2026 14:41
74 lines
4828 bytes
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.

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 signed char return is unusual; why not 'int'? (How would you even 
>> print an 'err_t' value anyway)?
> 
> It seems that yet again, you need an explanation of fundamental points 
> of software development.  Today's lesson is on "abstraction".

OK. I've just looked at several graphics libraries. Those have chosen to 
use predominantly standard C types for function return values. And 
standard C types for numeric arguments.

Sometimes they might be prefixed, eg. GL_int, SDL_bool, probably as 
abstraction from the vagaries of standard C.

It seems a trend to invent pointless extra types for everything. In C 
itself, there are about 35 denotations for integer types, and that's 
before you get into clock_t, time_t, offset_t and everything else.

In general most boil down to one of i32 u32 i64 u64.

So you can go over the top with abstraction.

> Maybe on some targets (of this portable library), err_t is "signed 
> char".

Why not define it on top of 'int'? Is it likely that large numbers of 
error codes are going to be stored within structs and arrays so that the 
size must be minimal?

> 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.


> Or look at the "ip_addr_t" type.  It happens, at the moment, to be a 
> struct.  But it might have been a union.  The size and contents of the 
> struct depend on details of how the library is built - whether it has 
> support for ipv4, ipv6, or both.  Maybe a future version will also 
> support ipv8, or ipv5 (I've heard some people are trying to make an IP 
> protocol that covers more than IPv4, but without most of the 
> complicating additional features of IPv6).  It is an abstract type - you 
> use it without knowing the details.

I haven't said much about that. It is a struct so some username is 
needed. I renamed it to IP_addr in my example.

But I'm not sure it needs the _t suffix. (Is it a thing now for every 
typedef name to need _t?)

I notice however that the argument is a pointer: if ip_addr_t* values 
are commonly passed around, I would put an abstraction around that.

(However that's partly because how my language works is different; to 
access a member of the struct, I don't need to know if the type of X is 
an actual struct or is a pointer to one; I write X.addr in both cases.)

Technical Details
Message-ID: <11baiuc$11ac$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> <11arjmc$2qid7$1@dont-email.me> <11at5vi$5vu$1@reader2.panix.com> <11auad0$3no1k$1@dont-email.me> <11aupfl$3ul$1@reader2.panix.com> <11avmfb$55rt$1@dont-email.me> <11b2a6d$131h6$1@dont-email.me> <11b2hr6$15thq$1@dont-email.me> <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me> <11b35gt$1cn63$2@dont-email.me> <11b557o$1kr9u$1@dont-email.me> <11b56uo$1q18k$5@dont-email.me> <11b6224$2ejik$1@dont-email.me> <11b774o$2m8c9$3@dont-email.me> <11b7k22$2v8e5$1@dont-email.me> <11b7ogt$2m8c9$5@dont-email.me> <11b933e$3h3d0$1@dont-email.me> <11ba78m$3peq3$3@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!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 15:41:16 +0100
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <11baiuc$11ac$1@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me> <11arjmc$2qid7$1@dont-email.me>
 <11at5vi$5vu$1@reader2.panix.com> <11auad0$3no1k$1@dont-email.me>
 <11aupfl$3ul$1@reader2.panix.com> <11avmfb$55rt$1@dont-email.me>
 <11b2a6d$131h6$1@dont-email.me> <11b2hr6$15thq$1@dont-email.me>
 <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me>
 <11b35gt$1cn63$2@dont-email.me> <11b557o$1kr9u$1@dont-email.me>
 <11b56uo$1q18k$5@dont-email.me> <11b6224$2ejik$1@dont-email.me>
 <11b774o$2m8c9$3@dont-email.me> <11b7k22$2v8e5$1@dont-email.me>
 <11b7ogt$2m8c9$5@dont-email.me> <11b933e$3h3d0$1@dont-email.me>
 <11ba78m$3peq3$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 21 Oct 2026 14:41:16 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="34124"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/RAXxXWPbwN0x/YcTdvZa+"; posting-host="c65e78a22dc81d6f5c20317bcf66a407"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tJAAQiGC9EBrDxnm3vhO2EUJhm4= sha256:rth64CKm3WHNmnEth2MK0V0JsTnOpxy5jNXEh0BgA/8=
	sha1:4q1TZlwQMJ2+lBCIfxrBCRBuvvQ= sha256:xfTMXe0rQ9cjGfTNkRZY1lhBDVvVR6K3DC6YxybDA/U=
In-Reply-To: <11ba78m$3peq3$3@dont-email.me>
Content-Language: en-GB