Article View: comp.lang.c
Article #529Re: Taming The Switch-Statement
From: Waldek Hebisch
Date: Sun, 18 Oct 2026 23:51
Date: Sun, 18 Oct 2026 23:51
67 lines
4201 bytes
4201 bytes
Dan Cross <cross@spitfire.i.gajendra.net> wrote:
> In article <11b2pq5$3pvda$7@dont-email.me>,
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>>On 2026-10-18 16:13, Michael S wrote:
>>> On Sun, 18 Oct 2026 14:34:28 +0200
>>> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>>>> On 2026-10-18 14:09, David Brown wrote:
>>>>>
>>>>> [...]Â (I don't know why N3377 proposed "do { } while NAME ( )"
>>>>> rather than "do NAME { } while ( )". )
>>>>
>>>> Oh! - I can only think that it would then be (sort of) "consistent"
>>>> with the place of the label attacked in a 'while' loop; i.e. behind
>>>> the 'while' keyword. - It's inconsistent in another interpretation,
>>>> though; and I'd certainly have favored the latter form, to have the
>>>> label consistently attached at the loop-entry keyword.
>>>
>>> I'd prefer label consistently attached to the loop-exit keyword.
>>
>>I can see that this might look appealing in case of 'break'. In
>>case of the same mechanism working also for 'continue' I'd then
>>think that it should generally better be an "attribute" of the
>>loop entry keyword, i.e. placed where loops start. (But that's
>>just my opinion.) Having it at a different place with a do-loop
>>I consider a really bad decision. It's advantageous to know the
>>direction in which to seek for the label if you inspect code. -
>>But okay, it's "C"; I won't heat up about some future C-release
>>that I'll never use (especially given that I'm not even be using
>>all of those more recent additions that are already available).
>
> I think colocating it with `do` might create a syntactic
> ambiguity. In the case of `for`, `while`, and `select`, there
> is a required token following the keyword (the `(`). However,
> for a `do`/`while` loop, `do` is followed immediately by a,
> `secondary-block` production. In particular, you do not _need_
> braces to denote a compound statement after `do`; something like
> `do i++; while (i < j);` is perfectly legal in C.
>
> In the N3377 proposal, the new `block-name` is just an
> identifier. If it were allowed immediately after the `do`, then
> given, `do NAME statement; while(condition);` you can't tell
> `NAME` from the name of the loop and a random identifier before
> a statement; something like `do LOOP i++; while (i < j);`
> appears as though it _would_ be be syntactically valid by N3377
> as presently worked, but is the programmer's intent to create a
> loop name, or should this just be a syntax error?
>
> By requiring the block-name between a keyword and a
> syntactically required `(`, you remove that ambiguity: if there
> is an identifier there, then it is a `block-name`; if not, then
> the block has no name.
AFAICS this is worse, both:
do (i++); while (i < j);
and
do LOOP(i++); while (i < j);
are currently legal (assuming that 'LOOP' is a function).
Writing statement with parentheses may look silly, but such code
may be easily produced due to use of macros.
--
Waldek Hebisch
Technical Details
Message-ID:
<11b3m1r$3tp6p$1@paganini.bofh.team>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!newsfeed.bofh.team!paganini.bofh.team!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2pq5$3pvda$7@dont-email.me> <11b3gkj$mt2$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Sun, 18 Oct 2026 23:51:25 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11b3m1r$3tp6p$1@paganini.bofh.team>
References: <119qf6l$2rmg3$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2pq5$3pvda$7@dont-email.me> <11b3gkj$mt2$1@reader2.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 18 Oct 2026 23:51:25 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="4121817"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2