🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #304

Re: Taming The Switch-Statement

#304
From: bart
Date: Mon, 12 Oct 2026 23:53
53 lines
3349 bytes
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. Even though he says this:

"I've used the ability to fall through in a significant fraction (50% in 
some applications) of the switch statements"

So 50% /sometimes/, and not even individual case-blocks, but of those 
switch statements which use at least one fall-through, if I read that right.

So even for him, the majority of case-labels do not fall through.

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!

> Speaking for myself, I had to learn *once*, several decades ago,
> that each case needs to end with "break;" (unless I want fallthrough
> behavior).  As I've mentioned here before, I pretend that the "break;"
> is part of the syntax of a switch statement, while being aware that
> it really isn't.
> 
> It's easy, and it doesn't hurt a bit.  I'll bet it would be easy
> for you if (a) you regularly wrote C code (I don't know how often
> you do) and (b) you didn't go out of your way to suffer on other
> people's behalf.
> 

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.

And also:

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

These are practical workarounds. That 'break; case' was part of a 
solution I used for a 20Kloc C application.

Technical Details
Message-ID: <11ajrt0$382u$1@dont-email.me>
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: <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>

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: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Tue, 13 Oct 2026 00:53:04 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <11ajrt0$382u$1@dont-email.me>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 12 Oct 2026 23:53:04 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="106590"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18jSVtAMFiaaujNOAf1VZDG"; posting-host="77c9fe16ce3505b18aae67dd9ba4b8ee"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jyKCHwSnwp1Rp9VC2liE8381LLM= sha256:Mmiz4Hp4/xylUoNoCFf21kQGIt3u6iOQSMC0TnB6sHo=
	sha1:V8S/39XbugZKOUEnT900+p2DHY8= sha256:2/nAXwBN2C0/UXzQ+HQcjdikBBDft5V+4IL/RcAUsfo=
In-Reply-To: <11ajqhc$28f2$2@kst.eternal-september.org>
Content-Language: en-GB