Article View: comp.lang.c
Article #428Re: Taming The Switch-Statement
From: bart
Date: Thu, 15 Oct 2026 18:59
Date: Thu, 15 Oct 2026 18:59
60 lines
3205 bytes
3205 bytes
On 15/10/2026 13:17, Tim Rentsch wrote:
> cross@spitfire.i.gajendra.net (Dan Cross) writes:
>
>> In article <11aoqa9$1rgda$1@dont-email.me>, bart <bc@freeuk.com> wrote:
>>
>>> On 14/10/2026 20:30, Dan Cross wrote:
>>> [snip more of the same already hashed and rehashed ad naseum]
>>>
>>> As for multiple nested loops, this will fix that too, that's great. We
>>> just require some real examples of that being needed!
>>
>> Here's a pretty terrible way to write part of a lexical
>> analyzer. I just typed this in an hour or so ago.
>>
>> [200+ lines of code]
>
> This code provides an excellent example of why multi-level breaks
> should not be added to C.
Actually most of those 'break-labels' are not multi-level breaks.
But they have to use that form because they are inside 'switch'.
(Unless you consider 'levels' to include switch statements as loops; I
don't. I mean, there is a 'continue' in there too inside switch, which
doesn't use the label. So how can that not be multi-level but 'break' is?)
It all goes back to that bad decision about 'break' that everyone is
playing down.
> The code would be easier to understand
> if all the 'break <label>;' lines were replaced with one of 'goto
> TOKEN_COMPLETE;' or 'goto COMMENT_COMPLETE;', as appropriate,
> and with the loop labels being removed and the two new labels put
> in at the appropriate places.
Once you have to write /actual labels/, which aren't even in local scope
within the loop, then 'break label' doesn't buy much over 'goto label':
loop:
while () {
switch () {
case x:
break loop;
}
}
while () {
switch () {
case x:
goto loopend;
}
}
loopend:
The latter will at least work with every compiler.
Technical Details
Message-ID:
<11ar7rb$2mb01$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-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11ao8af$1k8p3$1@dont-email.me> <11aol8k$adq$1@reader2.panix.com> <11aoqa9$1rgda$1@dont-email.me> <11apa4b$kv$1@reader2.panix.com> <86bj8vqhtl.fsf@linuxsc.com>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: Thu, 15 Oct 2026 19:59:54 +0100 Organization: A noiseless patient Spider Lines: 60 Message-ID: <11ar7rb$2mb01$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11ao8af$1k8p3$1@dont-email.me> <11aol8k$adq$1@reader2.panix.com> <11aoqa9$1rgda$1@dont-email.me> <11apa4b$kv$1@reader2.panix.com> <86bj8vqhtl.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 15 Oct 2026 18:59:55 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2829313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192nYmaRh0/noOGQBHE/p3t"; posting-host="3f7a5532ffaf673b54a2292b8a86a9eb" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:8Sfzmmy1OCvN6EHyE+U/Y61xxDs= sha256:OOyZnx0TgAZ+qt1iZ5ZIIphcGxzQz4wuYPinNBWkjWU= sha1:SX/fdCmSgMqQ3DsHWiT9Kz9Fezk= sha256:qiBA3Unukk0Jypebf1kkrZdjuUMcI9u6wJxG4kZgFA8= In-Reply-To: <86bj8vqhtl.fsf@linuxsc.com> Content-Language: en-GB