🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #494

Re: Taming The Switch-Statement

#494
From: Janis Papanagnou
Date: Sun, 18 Oct 2026 11:39
94 lines
5466 bytes
On 2026-10-18 12:48, David Brown wrote:
> 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.

You've noticed my smiley? (There was no need for an explanation.)

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

"C" is "C", and Tim is Tim. (And we know both sufficiently.) :-)

> 
>>
>>>
>>> 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.)
>>

(I interpret your following explanations as additional information.)

> 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.

Yes.

> 
> 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.)

Thanks. I'm interested, but (given what I think about it) not that
much. :-)

> 
>>
>> 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.

Well, I don't know what Emacs supports, or what it doesn't support so
that it requires some workaround, or shortcut, or explicit help from
the programmers concerning the layout.

I was using Vi for decades and with a search command ('/') you can do
a regexp '/^fname' to find fname at the start of a line. But there's
also "ctags" that can be used to facilitate that (and more). Recently
(i.e. since 25+ years) I'm using Vim where there's additional facilities
like the commands 'gd' (and 'gD') to jump to the local (and "global")
declaration of an entity; the latter don't require a tags-database or
any specific source code formatting to find the names.

Personally I've never followed the function-type-on-an-own-line style.

Janis
Technical Details
Message-ID: <11b2b6e$3pvda$4@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> <11b285v$121v2$2@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: Sun, 18 Oct 2026 13:39:58 +0200
Organization: A noiseless patient Spider
Lines: 94
Message-ID: <11b2b6e$3pvda$4@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>
 <11b285v$121v2$2@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 11:39:59 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3997098"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19mbmDU9+ccFDZtL+WLVX5H"; posting-host="413ca35758bf2644217f2957a34a3916"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8nTJr3OvVUUr1OXYZRSSz6SVQbk= sha256:p9JO7q6J14uWe5dO5KEXE5GeOU4AK14gSXg8KO6eIBs=
	sha1:SJ8cAsC37nlT9qOOgRtrSW8MdLQ= sha256:NiQpkq0LNOfrPu/y6kDHWcUAYIdIuaSdiLXxV9vrF4E=
Content-Language: en-US
In-Reply-To: <11b285v$121v2$2@dont-email.me>