🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #486

Re: Taming The Switch-Statement

#486
From: David Brown
Date: Sun, 18 Oct 2026 10:48
61 lines
4244 bytes
On 17/10/2026 01:29, Janis Papanagnou wrote:
> On 2026-10-17 00:00, Keith Thompson wrote:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> [...]
>>>> There's a proposal for C2y to use goto labels as loop names, and a
>>>> competing one to define a new syntax like "for NAME (;;)" :
>>>> [...]
>>>
>>> I'm not particularly a fan of multi-level break/continue.  But if
>>> we're going to have one of these, the second ("for NAME (;;)") is
>>> unquestionably better.
>>
>> Unquestionably?  Why?
> 
> Why would one question an opinion? ;-)

Time didn't word it as a personal opinion - he made it clear that he 
doesn't think anyone else could have a different opinion.

The C standards committee collectively reached an agreement counter to 
Tim's thoughts, so clearly his preferred variant is /not/ unquestionably 
better.

> 
>>
>> I do like the fact that it doesn't conflate goto labels with loop
>> names, but I still prefer the "NAME: for (;;)" form, partly because
>> it's consistent with several other languages.
> 
> I've no strong opinion on that, but I find the "for NAME (;;)" to
> clearer express the _local scope_ of embedded breaks or continues.
> (Just a matter of taste, and my appreciation for locality.)
> 

A main objection to "name: for ..." is that with function-scope labels, 
you need a new name for every labelled loop or switch.  That may be an 
inconvenience, especially for macro with labelled loops, or for 
copy-and-paste code.  There is a proposal to deal with that which 
basically says :

1. Any "break label;" or "continue label;" refers to the innermost 
containing loop or switch with that label.

2. Any "label" used in "goto label;" must be unique in the function.

Those rules give a simple and intuitive fix without affecting existing code.

Beyond that, "name: for ..." or "for name ..." is, as you say, mostly a 
matter of taste.  (There are proposals for both versions, and you can 
look them up to see the arguments.)

> 
> As far as I recall, in "C", the name of the function was often put
> separately (first in the line) to have an easy method to find its
> declaration by simple "grep ^fname". (With any sophisticated editor
> this might be a weak argument, though.)
> 

I think it was popularised with a shortcut in emacs.
Technical Details
Message-ID: <11b285v$121v2$2@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> <11ac0mi$19kfd$1@dont-email.me> <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org> <11ad5eq$1l8hg$1@dont-email.me> <11ad9fg$cjm0$4@dont-email.me> <11addhr$1oakb$1@dont-email.me> <11aduuk$cjlv$1@dont-email.me> <20261010220212.000063fd@yahoo.com> <11ae56o$cjlv$4@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>

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: Sun, 18 Oct 2026 12:48:31 +0200
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <11b285v$121v2$2@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me>
 <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org>
 <11ad5eq$1l8hg$1@dont-email.me> <11ad9fg$cjm0$4@dont-email.me>
 <11addhr$1oakb$1@dont-email.me> <11aduuk$cjlv$1@dont-email.me>
 <20261010220212.000063fd@yahoo.com> <11ae56o$cjlv$4@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 18 Oct 2026 10:48:32 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1116130"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+5vG8SL0Ugz3ui3LbjitHF9S2BCKHXwac="; posting-host="a272f2752d0a4376a695806f42b83d2a"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:h76mBnnzfEzSS1XHBvhFoL9VNHs= sha256:Ve/TxDrMbrRRwMZxVGwNwjWsqGbFDDtglKAzrL3f08Q=
	sha1:lymYMf7t3mZjRcqYO3FnpBkNsM4= sha256:CuiOOWUKUXRtDnu6UbQMHWxM7vRmdzjgngK4OX9Ar6I=
In-Reply-To: <11auc0s$206gh$3@dont-email.me>
Content-Language: en-GB