Article View: comp.lang.c
Article #298Re: Taming The Switch-Statement
From: Dan Cross
Date: Mon, 12 Oct 2026 22:35
Date: Mon, 12 Oct 2026 22:35
46 lines
2836 bytes
2836 bytes
In article <5W9zS.161421$98z8.84067@fx33.iad>, Scott Lurndal <slp53@pacbell.net> wrote: >cross@spitfire.i.gajendra.net (Dan Cross) writes: >>In article <11aidi3$3gbu4$1@dont-email.me>, bart <bc@freeuk.com> wrote: >>>On 12/10/2026 06:22, David Brown wrote: >>>> On 12/10/2026 00:05, bart wrote: >>> > >>I kinda sorta agree that requiring `break` between `case` >>statements in C was an historical mistake, but here we are: it >>is 2026, and the language has done that for more than 50 years >>now. The ship for changing it has sailed. What is one left to >>do, besides acknowledging it as a wart on the face of the >>langauge? > >I, on the other hand, don't consider it a mistake, in the >context of the C and C++ languages. I've used the ability to >fall through in a significant fraction (50% in some applications) of >the switch statements that I've written over the last >five decades of C and C++programming. Yeah, that's why I'm waffling by only "kinda sorta" agreeing, while means I'm also "kinda sorta" disagreeing. :-D Personally, I think that the BCPL `valof`/`resultis` thing is pretty cool and would have liked to see something like that in C, which in many ways would have subsumed this and other issues. But I honestly doubt they could have fit that into a C compiler meant to run on a PDP-11/20. >Absent other changes to the syntax (e.g. non-contiguous ranges >in the case selector[*]) the requirement to use break to avoid >falling through to other cases is rather valuable to me. I, too, would have liked to have seen ranges and mulitiple case values, at least. Rust has this, and it is genuinely useful. You can even do something analogous to duff's device in Rust, but it's hideous: https://huonw.github.io/blog/2025/03/rust-fallthrough/ Man, that sure looks like it got whacked by an ugly-stick, don't it? - Dan C.
Technical Details
Message-ID:
<11ajnc4$f7l$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> <11aidi3$3gbu4$1@dont-email.me> <11aj5nt$t7t$1@reader2.panix.com> <5W9zS.161421$98z8.84067@fx33.iad>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: Mon, 12 Oct 2026 22:35:48 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11ajnc4$f7l$1@reader2.panix.com> References: <119qf6l$2rmg3$1@dont-email.me> <11aidi3$3gbu4$1@dont-email.me> <11aj5nt$t7t$1@reader2.panix.com> <5W9zS.161421$98z8.84067@fx33.iad> Injection-Date: Mon, 12 Oct 2026 22:35:48 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="15605"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross)