Article View: comp.lang.c
Article #326Re: Taming The Switch-Statement
From: Janis Papanagnou
Date: Tue, 13 Oct 2026 11:33
Date: Tue, 13 Oct 2026 11:33
91 lines
5977 bytes
5977 bytes
On 2026-10-13 12:26, bart wrote:
> On 13/10/2026 11:12, Janis Papanagnou wrote:
>> [...]
>> I'm aware that one might wants to pass and process two values
>> from a function (as I interpreted one of bart's recent code
>> fragments), but then, and if it would be "impossible" to avoid
>> that pattern, I'd just add a condition
>>
>> int leaving = 0;
>> while ((token = parse (&token...)) != ERROR && !leaving)
>> switch (token)
>> case END_TOKEN: leaving = 1; ...
I just wrote that down without thinking, so I take the opportunity
to correct that. In practice you would better swap the conditions
and name the return code variable correctly
while (!leaving && (rc = parse (&token...)) != ERROR)
>>
>> that's really trivial and straightforward, and it's beyond me
>> why anyone (but bart, of course) would see a problem here.
>
> Because it's a hack.
Your "definitions" are generally very peculiar, and they regularly
have been considered here to not reflect what typical sane people
would say about standard code patterns and programming. - I can
only explain your personal valuation if I assume that your thinking
is working in an extremely narrow corridor.
> But if this is acceptable, then why does C even
> have loop-break? Since there is always some workaround (or 'writing
> code' as David Brown puts it.)
This has already been explained so often, implicitly and explicitly,
that I don't know why you're asking it again and again. - Are you
really interested to hear all that again?! - Your perception and
comprehension appears to be like a human /dev/null. - Okay, again...
There are two principal and common "operation modes" with branches
of switch-like constructs; to leave after the the tagged commands
have been processed or to continue with the subsequent commands
("fall-through"). Various (also historic) languages do not support
a fall-through but have even more limits on their counterpart of
switch. The "C" designers decided to support both. Being a low-level
language they designed it with primitive semantics but to allow full
expressive flexibility. There are a few options how to distinguish
the switch "operation-modes". Some languages indicated both cases
(Kornshell, for example with ';;' and ';&' respectively). "C" has
decided to indicate syntactically just one of the cases explicitly,
_the case when the linear control flow is disrupted_; that thought
makes also sense since it matches the other possible "jumps", that
are existing with 'continue', 'return', 'exit()', 'goto'.
This should (again) explain what you asked with your question. (But
we also know that you aren't really interested in the answer; your
questions are obviously and mostly just your expression of "I don't
like the situation with C".)
>
> What would be the consequences of C not having it: would they be
> positive or negative overall?
Before I "met" you, bart, I would have guessed that any other
choice of implementation of 'switch' in "C" would not have made
and significant difference. Now I'd say, if the design would have
been different then it would be much better, since then we could
spare us all the pointless posts with you. (But of course you'd
then find other complaints and in practice nothing would change
anyway.)
>
> Now apply the same analysis to a hypothetical loop-break that works
> inside switch.
I (and others) have explicitly answered that in other posts. - I'm
sorry that you were incapable of understanding those explanations.
No; I won't repeat it once again. - As homework I ask you to pick
all those posts, read them, try to understand them, and create a
written summary. (By that process pupils usually learn something.)
Janis
PS: Note that I usually completely skip your posts - that's why you
only very rarely see a reply unless I see you quoted in another post
- and I've opened this post of you only because I thought you might
have commented on my little mistake above that I intended to correct.
So generally you can spare your meaningless replies to my posts and
save your (and others') time.
Technical Details
Message-ID:
<11al4u0$4o6m$3@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-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <20261010220212.000063fd@yahoo.com> <11ae56o$cjlv$4@dont-email.me> <20261010230355.00005189@yahoo.com> <864iesjx6e.fsf@linuxsc.com> <11afvqt$2kloc$1@dont-email.me> <11ag37o$2ln0a$1@dont-email.me> <11agbsh$2pbk7$1@dont-email.me> <11aggaq$2qqh9$1@dont-email.me> <11agils$2s3tg$1@dont-email.me> <11agv1t$30q22$2@kst.eternal-september.org> <20261012220256.00003d07@yahoo.com> <11ajb95$3t8jj$1@dont-email.me> <20261012223144.00000f95@yahoo.com> <11akm9q$29tpl$1@paganini.bofh.team> <11al05t$4o6l$1@dont-email.me> <11al10u$eiet$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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Tue, 13 Oct 2026 13:33:20 +0200 Organization: A noiseless patient Spider Lines: 91 Message-ID: <11al4u0$4o6m$3@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <20261010220212.000063fd@yahoo.com> <11ae56o$cjlv$4@dont-email.me> <20261010230355.00005189@yahoo.com> <864iesjx6e.fsf@linuxsc.com> <11afvqt$2kloc$1@dont-email.me> <11ag37o$2ln0a$1@dont-email.me> <11agbsh$2pbk7$1@dont-email.me> <11aggaq$2qqh9$1@dont-email.me> <11agils$2s3tg$1@dont-email.me> <11agv1t$30q22$2@kst.eternal-september.org> <20261012220256.00003d07@yahoo.com> <11ajb95$3t8jj$1@dont-email.me> <20261012223144.00000f95@yahoo.com> <11akm9q$29tpl$1@paganini.bofh.team> <11al05t$4o6l$1@dont-email.me> <11al10u$eiet$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 13 Oct 2026 11:33:20 +0000 (UTC) Injection-Info: dont-email.me; logging-data="155862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18W3Df0ClRJ0ZeYFF4Kg07G"; posting-host="a1215c61e514a50645aa60546bc3740b" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:uvfKy5J+zc33LSMGbcLs/WJ2jaY= sha256:WW/uiUkKaWt395nammFzeIrwwftd+9gTfOLlgb6/ibk= sha1:GYnS8ruXXLHrrNE2IO/7BFB/xpc= sha256:sk/aU5hg5S/kHf9irIF1XrN/68XM7S/v7NXvcoExu+o= In-Reply-To: <11al10u$eiet$1@dont-email.me> Content-Language: en-US