Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #402823

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

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 2026-10-08 01:31 +0000
Organization A noiseless patient Spider
Message-ID <20261007182218.446@kylheku.com> (permalink)
References <EUBxS.8919$mPXe.2290@fx06.ams4>

Cross-posted to 3 groups.

Show all headers | View raw


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

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-08 08:58 +0800
  Re: Real world switch () with the MPS memory pool system! Kaz Kylheku <046-301-5902@kylheku.com> - 2026-10-08 01:31 +0000
    Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-10 04:26 +0800
      Re: Real world switch () with the MPS memory pool system! Kaz Kylheku <046-301-5902@kylheku.com> - 2026-10-09 20:45 +0000
        Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-10 05:02 +0800
          Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-11 09:28 +0800
      Re: Real world switch () with the MPS memory pool system! tfb <tfb@work.it.out> - 2026-10-10 09:45 +0000
        Re: Real world switch () with the MPS memory pool system! George Neuner <gneuner2@comcast.net> - 2026-10-11 01:13 -0400
          Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-11 14:45 +0800
          Re: Real world switch () with the MPS memory pool system! tfb <tfb@work.it.out> - 2026-10-11 07:28 +0000
            Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-11 15:41 +0800
            Re: Real world switch () with the MPS memory pool system! George Neuner <gneuner2@comcast.net> - 2026-10-11 05:29 -0400
  Re: Real world switch () with the MPS memory pool system! Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-08 06:03 -0700
  Re: Real world switch () with the MPS memory pool system! ram@zedat.fu-berlin.de (Stefan Ram) - 2026-10-09 14:30 +0000
    Re: Real world switch () with the MPS memory pool system! Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-10 04:41 +0800

csiph-web