Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Fri, 16 Oct 2026 04:46:03 -0700 Organization: A noiseless patient Spider Lines: 60 Message-ID: <86v771q35w.fsf@linuxsc.com> References: <119qf6l$2rmg3$1@dont-email.me> <119r8u3$34nce$1@dont-email.me> <119rau4$35ugq$1@dont-email.me> <20261005142208.51@kylheku.com> <11a1clv$1dg97$1@kst.eternal-september.org> <11a1hge$1gpor$1@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 16 Oct 2026 11:46:04 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3382761"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FcLTmwRo6yr7SxqAE4X5ls1gTrlbDOqM="; posting-host="6aa7975ca949d05eced06ab246205481" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:9fBv5sGQbwimnMNWYAzHOpdZvR0= sha1:AiO9x3DB2iDv+Yh8MQd5cSiC25E= sha256:XQATFwdVSFa+67mxqzKjgkYVntEKeMJzVNAQZAvHlXw= sha1:ydHZnnwD0U3scZ29n1Aogjpydv0= sha256:ywhk/4EfW+5NN6fHq3WDCIFC229Yl0nrZ7QHiW2tWC4= Xref: csiph.com comp.lang.c:403212 Keith Thompson writes: > [.. some syntanx changes were made as part of C23 ..] > > C23 made some changes with the goal of allowing a label to be > immediately followed by a declaration or `}`. It did so by changing > the grammar for a compound-statement: > > compound-statement: > { block-item-list[opt] } > > block-item-list: > block-item > block-item-list block-item > > block-item: > declaration > unlabeled-statement > label > > This means that in > > switch (x) { > case 'A': > case 'B': > case 'C': > puts("blah"); > } > > *there is no labeled-statement*. Instead, each of `case 'A':`, > `case 'B':`, `case 'C':`, and `puts("blah");` is a block-item, and all > the block-items are at the same syntactic level within the > compound-statement. (The indentation is still appropriate IMHO.) > > Since control jumps to "the statement or declaration following the > matched case label", there is no fallthrough. If x == 'A', control > jumps directly to the puts() call. > > In C17 and earlier, the same wording implies that when x=='A', control > jumps to the statement > case 'B': case 'C': puts("blah"); > so one might arguably refer to that as "fallthrough". In C23, > case 'B': case 'C': puts("blah"); > is not a statement. > > A weird but mostly harmless consequence of this is that C23 keeps > the syntactic construct of a *labeled-statement*, but it's used > extremely rarely. Any C17-or-earlier labeled-statement at the > top level of an enclosing compound-statement is no longer a C23 > labeled-statement, even though it looks like one. In C23, a > labeled-statement can only occur in an odd construct like this: > > if (condition) > LABEL: statement; > > The proposal that led to this suggested an optional additional change, > making labels outside of compound statements an obsolescent feature. > That part of the proposal was not adopted. Glad to hear it. Good choice.