🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #596

Re: Taming The Switch-Statement

#596
From: David Brown
Date: Tue, 20 Oct 2026 07:05
56 lines
4358 bytes
On 20/10/2026 00:28, Keith Thompson wrote:
> David Brown <david.brown@hesbynett.no> writes:
>> On 19/10/2026 12:50, Keith Thompson wrote:
> [...]
>>> The odd scoping rules for labels don't bother me either.  They mean
>>> you can't have two loops or switch statements with the same name in
>>> the same function.  I can barely imagine that being inconvenient.
>>
>> I can imagine that being a bit inconvenient in some cases, but I think
>> the proposal in N3658 would simply and cleanly fix that.
> [...]
> 
> *If* the fact that labels (which are now also loop/switch names)
> follow strange scope rules is a real problem, N3658 is probably
> the best practical solution.  I'm slightly uncomfortable with the
> idea of an entity's scope depending on how it's used, not just how
> it's defined.  I think it introduces a complication to the language
> without much real benefit.

I can understand the feeling here - it would mean "L1: ; L1: ;" is fine 
until you also add "goto L1;".  But it is simply saying that the real 
problem is not duplicate labels - it is ambiguity in the target label.

> 
> But cleaner solutions are impractical.

I think that is correct.

> 
> IMHO the only really clean solution would be to make labels and
> loop/switch names distinct, keep the existing scoping rules for
> labels, and use more normal scoping rules for loop/switch names.
> And if the "while NAME (...)" proposal were accepted, that's probably
> how it should work.  (But I prefer having the name as a prefix of the
> loop or switch statement.)

We cannot have an ideal solution here - there are always compromises 
when new features are added to existing languages.

> 
> If N3658 were adopted, it wouldn't bother me much.  I just don't
> think it's necessary.
> 

I do see benefits to it.  I don't think it will make much difference to 
code in practice - after all, the great majority of functions in C do 
not have any labels, any gotos, or any use of multi-level breaks.  But 
it conveniently negates one of the big disadvantages of the prefix label 
syntax for named control structures.  There are code bases where there 
are macros containing loops that might benefit from this, and I can 
imagine it being helpful for generated C code (which is sometimes 
label-heavy).



Technical Details
Message-ID: <11b73s7$2m8c9$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> <20261010230355.00005189@yahoo.com> <11ae7eb$cjlv$6@dont-email.me> <11aeee0$24k8m$1@kst.eternal-september.org> <11aer17$286ml$2@dont-email.me> <11aeusp$29hmu$2@kst.eternal-september.org> <86mrsdpcgp.fsf@linuxsc.com> <11au6pr$3mdne$1@kst.eternal-september.org> <11auc0s$206gh$3@dont-email.me> <11b285v$121v2$2@dont-email.me> <11b293j$12jfa$1@dont-email.me> <11b2cuh$141vj$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2mf1$16mof$2@dont-email.me> <20261018181623.00007978@yahoo.com> <11b347h$1cn63$1@dont-email.me> <20261018223859.000031d3@yahoo.com> <11b4n4s$1q18k$1@dont-email.me> <11b4smj$1vt4q$1@kst.eternal-september.org> <11b4t5k$1q18k$3@dont-email.me> <11b65hn$2fcat$1@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: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Tue, 20 Oct 2026 09:05:42 +0200
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <11b73s7$2m8c9$1@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me>
 <20261010230355.00005189@yahoo.com> <11ae7eb$cjlv$6@dont-email.me>
 <11aeee0$24k8m$1@kst.eternal-september.org> <11aer17$286ml$2@dont-email.me>
 <11aeusp$29hmu$2@kst.eternal-september.org> <86mrsdpcgp.fsf@linuxsc.com>
 <11au6pr$3mdne$1@kst.eternal-september.org> <11auc0s$206gh$3@dont-email.me>
 <11b285v$121v2$2@dont-email.me> <11b293j$12jfa$1@dont-email.me>
 <11b2cuh$141vj$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me>
 <20261018171339.00005308@yahoo.com> <11b2mf1$16mof$2@dont-email.me>
 <20261018181623.00007978@yahoo.com> <11b347h$1cn63$1@dont-email.me>
 <20261018223859.000031d3@yahoo.com> <11b4n4s$1q18k$1@dont-email.me>
 <11b4smj$1vt4q$1@kst.eternal-september.org> <11b4t5k$1q18k$3@dont-email.me>
 <11b65hn$2fcat$1@kst.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 20 Oct 2026 07:05:43 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2826633"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/p02nAESRJ+eeRB+1bbes/MM7jR2oiFXc="; posting-host="6609bebd5817c7daf1cbce2eb44e7728"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6YuStasL9M2kbP6gSB1axW1ccUQ= sha256:g4oMvucPPJNPDdiZyq4wUj9kORFvBy1vqvvdgnEyOw4=
	sha1:o8Tp4kv9C0puR4f1lFU245nQB34= sha256:yPKN5TzntMbedAYEw7PvXZm2AHE2zNeud6HaKLNPWjU=
In-Reply-To: <11b65hn$2fcat$1@kst.eternal-september.org>
Content-Language: en-GB, nb-NO