🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #54

Re: Real world switch () with the MPS memory pool system!

#54
From: Kaz Kylheku
Date: Thu, 08 Oct 2026 01:31
50 lines
2932 bytes
On 2026-10-08, Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote:
> static mps_res_t Type_isfwd_fn( mps_addr_t addr )
> {
>    Type_type type = addr ;
>    switch ( type->kind ) {
>    case Type_forwardType: return type->fwd ;
>    default: return NULL ;
>    }
> }

[...]

> So the question here is, do you think this is reasonable C code, and

Yes.

> would you write something similar yourself?  After all, /kind/ is an

As the initial draft, written by hand and not a whatever-to-C transpiler,
not the result of multiple rounds of maintenance, and not reasonably
expecting additional cases?

No.

I would write something more idiomatic:

  return type->kind == Type_forwardType ? type->fwd : NULL;

> enum, and the compiler might complain if you don't handle all the cases,

Such diagnostics tend to be suppressed in the presence of a default; it
is not possible for a switch not to handle all the cases when a default
case is present; it is most not reasonable to diagnose that which is not
possible, unless there is some good heuristic for suspecting that the
default should not actually be there.

> and not do that if you merely use an if ().  I wouldn't know, as I don't
> keep track of changes within G.C.C. nor clang anymore.
>
> Another question is, would you consider using the MPS memory pool system
> if you were to implement something garbage collected, like Common Lisp
> or ML [1]?

The intersection of "people who still write in C" and "people who want
to use someone else's C memory pool thing" is slowly converging to null.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID: <20261007182218.446@kylheku.com>
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: <EUBxS.8919$mPXe.2290@fx06.ams4>

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: Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups: comp.lang.c,comp.lang.misc,comp.lang.lisp
Subject: Re: Real world switch () with the MPS memory pool system!
Date: Thu, 8 Oct 2026 01:31:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <20261007182218.446@kylheku.com>
References: <EUBxS.8919$mPXe.2290@fx06.ams4>
Injection-Date: Thu, 08 Oct 2026 01:31:55 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3576213"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/LcPCkGIcmDK/m4YhCKL808KfLqqgCGLs="; posting-host="62ff1ac2475dddba581594ffba791706"
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:1R2l/WlFIUjxiujfa0tjjO06sMs= sha256:weU8TlDiAnpqUVnSrPY5l1kF68DnAXhqVGih0RTXTyk=
	sha1:1KVQtQe6IvSjcq626tNFsGfOlRM= sha256:8iz2LOsTGO1ghj9pIiYTwQfu8Xnek7PgbLR7iqY6pSs=