🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #306

Re: Taming The Switch-Statement

#306
From: Keith Thompson
Date: Tue, 13 Oct 2026 00:02
70 lines
3923 bytes
bart <bc@freeuk.com> writes:
[...]
> That's what it seems like: obstinately trying to pretend it is not a
> flaw, that it makes perfect sense, then you never want to do any of
> the stuff where it causes problems anyway etc.

Nobody is trying to pretend that there are no flaws.  The rest of
us acknowledge that C has flaws (though we don't necessarily agree
with what those flaws are) and then get on with writing working C
code in spite of those flaws.

Most of us are also aware of how very difficult it would be to "fix"
those flaws without breaking existing code.

You completely misunderstand where most of us are coming from,
even after it's explained to you.

> There are several issues discussed regarding switch:
>
> * That its structure is totally chaotic (there /is/ no structure)

An overstatement, but I don't entirely disagree.  switch is a low-level
control structure.  I'd say it's notable for its low-levelness even
compared to other C features.

> * That 'break' is needed to escape from the middle of that statement to
>   the end

Yes.  We all know that.

> * That that 'break' happens also to clash, needlessly, with loop-break

Yes, we all know that.  BCPL had BREAK and ENDCASE.  B apparently
dropped both, and then re-added just BREAK.  C inherited break
from B.  I haven't seen anyone say that that wasn't a mistake.
We just don't spend decades worrying about it.

Tell me, have this ever been a problem for you personally?  Have
you ever written a switch statement nested in a loop and wanted to
break out of the loop from within the switch?  (In C; I'm not asking
about your experience with other langauges.)  How much difficulty
has it really cause for you?

> * And also with 'case' only doing one label at a time, instead of
>   being able to do, for example: 'case a, b, c:' or 'case x...y',
>   although some of this is taken care of via extensions.

"case a, b, c:" is written as "case a: case b: case c:".  It's a little
more verbose than it needs to be.  It's very mildly annoying.

As for "case x...y", that's already proposed for C2Y, and is
documented in the N3886 draft.  You continue to whine about problems
that have already been solved.

> There's quite a lot that could have been done much better!

So invent a time machine and tell Dennis Ritchie to do it your way.

[...]

> Defending every shortcoming or quirk to the death seems common
> here.

No, it isn't.

[...]

-- 
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: <11ajsfi$28f2$5@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> <11agils$2s3tg$1@dont-email.me> <11ahpqi$38ir0$2@dont-email.me> <11ainqf$3kkvd$1@dont-email.me> <11aj73v$c2u$1@reader2.panix.com> <11ajcv8$3u33s$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 17:02:58 -0700
Organization: None to speak of
Lines: 70
Message-ID: <11ajsfi$28f2$5@kst.eternal-september.org>
References: <119qf6l$2rmg3$1@dont-email.me> <11agils$2s3tg$1@dont-email.me>
	<11ahpqi$38ir0$2@dont-email.me> <11ainqf$3kkvd$1@dont-email.me>
	<11aj73v$c2u$1@reader2.panix.com> <11ajcv8$3u33s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 13 Oct 2026 00:02:59 +0000 (UTC)
Injection-Info: kst.eternal-september.org;
	logging-data="74210"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/lqvoUqGZNzduS/6nxaeLv"; posting-host="11ac7c4b547d7ca6b42084bf5cca4a8e"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:1B+VhdghvUAQQ7KBXJrOfHfRjrs= sha256:Q8YB6pJSKegVURdjW+v0ur/lPi+ZH4lAOOS1SSOYn58=
	sha1:LDSfpX9J4m1fCBBgZfJk102gOn8= sha256:7Xmce/wyIToJuNudjEx4N8z/q5Ab45oWxRmJNiI94T0=