🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #308

Re: Taming The Switch-Statement

#308
From: Keith Thompson
Date: Tue, 13 Oct 2026 01:14
64 lines
3865 bytes
bart <bc@freeuk.com> writes:
> On 13/10/2026 00:29, Keith Thompson wrote:
>> bart <bc@freeuk.com> writes:
>> [...]
>>> So 99% of programmers have to suffer needing to pointlessly write
>>> 'break' everywhere, rather than the 1% having to write 'fallthru'.
>> We're not suffering.
>
> I was replying to SL who doesn't think auto-fall-through is a mistake
> because he uses it a lot.
[...]

And I was replying to your deeply silly claim that 99% of C programmers
"suffer" because we need to use "break" in switch statements.

[...]

> That makes it rather strange to favour the minority case when it would
> be more convenient and less typing for everybody, including SL, if it
> was the other way around!

Sure, it's strange.  A small minority of C programmers might prefer
to have fallthrough as the default.  The majority, I suspect, *would
have* preferred not to have fallthrough as the default.

Nobody other than you, as far as I can tell, thinks that the strange
choice made several decades ago has led to mass suffering.

[...]

> This is what I suggested in my first reply in the thread:
>
>    break; case a: case b:
>    break; case c:
>    break; default:;
>
> That is, use 'break; case' for the first case label of a block.

Yes, I suppose that would work, but frankly it looks weird.  If
you want to use that pattern in your own code, nobody is going to
stop you.  It reminds me of "Yoda conditions" (if (42 == x)), an
ugly coding practice that might make it slightly easier to avoid
a certain kind of error.

> And also:
>
> "Alternately, create a macro like 'endcase' that expands to 'break',
> for a more structured appearance."

All C programmers know that "break;" is how you terminate a case
if you don't want fallthrough.  A macro that expands to "break"
doesn't help anything.  I have to look up the definition to be sure
it's not doing something weird, and it doesn't address any of the
problems you've been complaining about.  And of course you still
have to remember that "break" in a switch in a loop doesn't break
out of the loop.  It appears to be an attempt to make C look like
some other language, something I've never found to be a good idea.

But again, if you want to use your "endcase" macro, nobody will
stop you.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID: <11ak0lr$28f2$7@kst.eternal-september.org>
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!kst.eternal-september.org!.POSTED!not-for-mail
References: <119qf6l$2rmg3$1@dont-email.me> <11ah16h$320sj$2@dont-email.me> <11ahqpu$38ir0$3@dont-email.me> <11aidi3$3gbu4$1@dont-email.me> <11aj5nt$t7t$1@reader2.panix.com> <5W9zS.161421$98z8.84067@fx33.iad> <11ajaa1$3ssqg$1@dont-email.me> <11ajqhc$28f2$2@kst.eternal-september.org> <11ajrt0$382u$1@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!kst.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Mon, 12 Oct 2026 18:14:35 -0700
Organization: None to speak of
Lines: 64
Message-ID: <11ak0lr$28f2$7@kst.eternal-september.org>
References: <119qf6l$2rmg3$1@dont-email.me> <11ah16h$320sj$2@dont-email.me>
	<11ahqpu$38ir0$3@dont-email.me> <11aidi3$3gbu4$1@dont-email.me>
	<11aj5nt$t7t$1@reader2.panix.com> <5W9zS.161421$98z8.84067@fx33.iad>
	<11ajaa1$3ssqg$1@dont-email.me>
	<11ajqhc$28f2$2@kst.eternal-september.org>
	<11ajrt0$382u$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 13 Oct 2026 01:14:36 +0000 (UTC)
Injection-Info: kst.eternal-september.org;
	logging-data="74210"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18p/DtzhOpFaflKnHIXbc5N"; posting-host="11ac7c4b547d7ca6b42084bf5cca4a8e"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:uTGPGrgB2HP6lpUXN1Dn5JTVsYw= sha256:TcQK/yb+V2xAciZgpucADT1Q2erDr4kbkOH8cuML+5k=
	sha1:GrsCpm64bhdzxnxzMt5fDvkvGGc= sha256:Ip0P6gV/qro07dMDXKIvVEkC8ieoM//sjhOxmKFvnLU=