Article View: comp.lang.c
Article #543Re: Taming The Switch-Statement
From: David Brown
Date: Mon, 19 Oct 2026 10:59
Date: Mon, 19 Oct 2026 10:59
64 lines
4794 bytes
4794 bytes
On 19/10/2026 12:50, Keith Thompson wrote: > David Brown <david.brown@hesbynett.no> writes: > [...] >> I can appreciate wanting a syntax that is distinct from regular labels >> for "goto". > > So can I. The first language I used that had this kind of thing > was Ada. In the language's initial design, it was decided that > though goto statements were needed, the labels should stand out: > > <<LABEL>> > -- ... > goto LABEL; > > Names used for loops have a lighter-weight syntax: > > LOOP_NAME: > while condition loop > -- ... > end loop; > > I can't think of a better syntax for loop names than "NAME:" (used > by several other languages), but in C that syntax is already > taken for goto labels. The possibility of any ambiguity between > "goto NAME;" and "break NAME;" doesn't bother me enough to want > to invent something new. And I consider the fact that other > languages use the "NAME:" syntax for loop names to be another > point in its favor. > > 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. > > And it's already specified in the latest C2y draft, and implemented in > gcc and clang, which means there's already some inertia against any > major changes. Anything could happen between now and the publication > of the next C standard, but I don't see any need to make significant > changes in this area. > > I use Perl's equivalent of named break quite a lot. I found > 31 occurrences of "exit NAME" in a collection of Perl scripts > I've written. I'm a little surprised to find that none of these > break out of nested loops; I just like to name loops for clarity. > I even find that having to choose a name for something forces > me to think more clearly about it. > > The C2y proposed syntax and semantics for named loops and switch > statements is of course imperfect, but it's reasonably clean > and useful. I see no need to make any significant changes in > this area. > There are always going to be disagreements about language features and syntax - even more so when they are added late to a language, rather than part of the initial design. (Maybe if named loops and "defer" were part of the original C, it would never have needed "goto" and labels.) Changes and additions have to be of enough potential benefit, and low enough cost or potential confusion - they don't have to be "perfect" or suit the needs and preferences of everyone.
Technical Details
Message-ID:
<11b4t5k$1q18k$3@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> <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> <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>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: Mon, 19 Oct 2026 12:59:00 +0200 Organization: A noiseless patient Spider Lines: 64 Message-ID: <11b4t5k$1q18k$3@dont-email.me> References: <119qf6l$2rmg3$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> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 19 Oct 2026 10:59:02 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1901844"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0Uq1P6ceEbmLD8Z1KOf335EdI8PRIuUU="; posting-host="f8e69aeaa618e660247a66e432a03539" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:z0LjV4DT4Av6GcRjmT7ctViWeVg= sha256:1e2+RDQ3yCi7GJBfTn6BG4GR3HvVC/eTfP48OBVe5Pc= sha1:z5gFoCE8eWliLyT4gACg2FmetYg= sha256:eDgKn41WlA/5IUOQkB5AV6rLfIOW9jJoT0QfH2lKMeE= Content-Language: en-GB, nb-NO In-Reply-To: <11b4smj$1vt4q$1@kst.eternal-september.org>