Article View: comp.lang.c
Article #295Re: Taming The Switch-Statement
From: Michael S
Date: Mon, 12 Oct 2026 21:25
Date: Mon, 12 Oct 2026 21:25
69 lines
3788 bytes
3788 bytes
On Mon, 12 Oct 2026 21:57:46 +0100
bart <bc@freeuk.com> wrote:
> On 12/10/2026 20:52, Scott Lurndal wrote:
> > bart <bc@freeuk.com> writes:
> >> On 12/10/2026 18:58, Dan Cross wrote:
> >>> In article <11ainqf$3kkvd$1@dont-email.me>, bart <bc@freeuk.com>
> >>> wrote:
> >>
> >
> >> This is my first example expressed in C (note those first three
> >> args are passed by reference):
> >>
> >> while (pmtype = nextcmdparam(¶mno, &name, &value, "m") {
> >> switch (pmtype)
> >> case pm_option: ...; break;
> >> case pm_sourcefile:
> >> if (passlevel == run_pass || passlevel ==
> >> runpcl_pass) { break;
> >
> > Aside from the incorrect syntax, it's really difficult to
> > determine your intent from this code fragment.
>
> Really? It's attempting to break out of the while-loop from inside
> that switch statement. What we've been discussing at length.
>
Thank you. You correctly identified the most common of the patterns
that triggered my response to Janis that started this particular
sub-thread.
The important part missing in your excerpt is that there are several
variables declared and initialized before loop and further processed
both within and after the loop.
> But it won't work like this because in this context, that 'break' is
> switch-break not loop-break.
>
>
> > It's likely that folks here could provide more idiomatic
> > C if you described the problem you're attempting to solve
> > rather than providing an incomplete and incorrect code
> > fragment.
>
> I'd be interested in the idiomatic C that doesn't involve rewriting
> my code or adding complexity in order to get around that silly clash.
>
As far as I am concerned, my most common workaround is goto. Others can
have other preferences.
It works well, but the need to invent the name of the label is a bit
annoying.
BTW, Ada/VHDL solution, with optional label before the loop also
suffers from this particular defect. Yes, it is more "structural" than
goto. It is considered important by many people, supposedly including
yourself. But on my personal ladder of preferences "structureness" by
itself is not particularly high as long as it does not bring another
benefits, like, for example, locality=reduced scope.
Technical Details
Message-ID:
<20261013002531.000025b8@yahoo.com>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-mailReferences:
<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> <GTazS.183760$ygUb.176068@fx23.iad> <11ajhka$3vuli$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!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Tue, 13 Oct 2026 00:25:31 +0300 Organization: A noiseless patient Spider Lines: 69 Message-ID: <20261013002531.000025b8@yahoo.com> 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> <GTazS.183760$ygUb.176068@fx23.iad> <11ajhka$3vuli$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Mon, 12 Oct 2026 21:25:33 +0000 (UTC) Injection-Info: dont-email.me; logging-data="4072047"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bw+TLN+dnS4l5IscUkzSMG2dnY3yAlW0="; posting-host="bd25255e15e86e7287fc154cd9715ad7" Cancel-Lock: sha1:l5kV+akueH+CpBuCPpS5I0YCvok= sha256:eaUVFzDbjckvFP0F5LY6BEhp57bQyg80fggzaWMyi0M= sha1:Yu1leGfJKfQb86tbavmrPWgrys0= sha256:ALigtcw1KUzs/ZiXqKXH5tBbpb03RligNEZosARVFTE= X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)