Path: csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "The long goodbye to C" by Eric Raymond Date: Fri, 17 Nov 2017 12:57:03 -0800 Organization: None to speak of Lines: 58 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="7bdb529bd75084c73bb3dbd08c9ca777"; logging-data="30090"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9N45dpHsCuYzIHMk568TX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:guDniArKNY9gsedHwNTrIgxcgL0= sha1:YdzOMIBmqsjYDwwgjL3k41wpBps= Xref: csiph.com comp.lang.c:122885 scott@slp53.sl.home (Scott Lurndal) writes: > Keith Thompson writes: >>BGB writes: >>[...] >>> the main problem with Duff's Device is that, to make it work, it would >>> require a deep search for case statements within other code blocks, and >>> to make the compiler be able to handle case statements found in places >>> other than directly inside a switch block. this would be a fairly >>> non-trivial piece of logic to add for a fairly rare edge case that could >>> probably be done instead using an explicit goto or similar. >> >>I don't know how difficult that would be, but all conforming C compilers >>do it. >> >>A case label can appear anywhere within a switch statement, whether the >>code is using Duff's Device or not. (I don't know of a case other than >>Duff's Device where that would be useful. That doesn't mean there are no >>such cases.) > > For me, I often have stuff like this: > > switch (something) { > ... > case CASE_1: > do_something(); > /* FALLTHROUGH */ > case CASE_2: > do_something_more(); > break; > } > > I still use the old lint(1) tags as well, for documentation > if nothing else. > > It's less common to fallthrough two or more cases, but I've > used duff's device in the past. Sure, but in your example the case labels are still at the top level within the switch statement. Or rather, they're at the top level of a compound statement that's controlled by the switch statement. The statement controlled by a switch is almost always a block statement, so any C compiler must at least be able to look one level down from the switch itself to find case labels. I'm not sure that limiting it to one level would make the implementation easier than a fully general (and conforming) approach. A conforming compiler must also handle silly things like this: switch (n) case 42: puts("hello"); (I've used Duff's Device myself, but only for comedic effect.) -- 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"