Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Spurious diagnostic messages Date: Wed, 27 May 2015 13:46:34 -0700 Organization: None to speak of Lines: 57 Message-ID: <87vbfdlped.fsf@kst-u.example.com> References: <871ti6rawv.fsf@kst-u.example.com> <3qh2ma1vojvb0add103h8tabbcb5gedhhb@4ax.com> <87d21lnckp.fsf@kst-u.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="21465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3tEGyZcsYYZawudkBZG6w" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:nvCK9MFva+ZP4yiwjw+k/iMrKl4= sha1:pTkcqPGzxZVJmtSuRXxIpUQhd1g= Xref: csiph.com comp.lang.c:62699 glen herrmannsfeldt writes: > Keith Thompson wrote: >> Morris Dovey writes: >> [...] >>> One that I've wondered about from time to time is > >>> switch (x) >>> { case { expression }: >>> /* case code */ >>> /* other cases */ >>> } > > (snip) >>> which causes the named function to be invoked to produce the >>> TRUE/FALSE result. > >> What's the point of specifying x in `switch (x)`? > > I presume x should be true (1). That seems unlikely. Given the proposed syntax: switch (x) { case { expr1 }: ...; case { expr2 }: ...; case { expr3 }: ...; default: ...; } I presume it would branch to the first case whose expression is true. What I don't understand from Morris's description is the relationship between x and the expressions. If x itself is expected to be true, then there seems little point in specifying it. (I'm probably making too big a deal over a minor oversight.) You could have an enhanced form of switch statement where the switch expression is somehow substituted into each of the case expressions. For example: int sign(int x) { switch (x) { case < 0: return -1; case == 0: return 0; case > 0: return +1; } } But defining the syntax and how it's evaluated would be non-trivial, and I'm not convinced it's that much better than an equivalent if/else chain that refers to x explicitly in each expression. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"