Article View: comp.lang.c
Article #323Re: Taming The Switch-Statement
From: Dan Cross
Date: Tue, 13 Oct 2026 10:52
Date: Tue, 13 Oct 2026 10:52
49 lines
3134 bytes
3134 bytes
In article <11ajsfi$28f2$5@kst.eternal-september.org>, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote: >[snip] >Yes, we all know that. BCPL had BREAK and ENDCASE. B apparently >dropped both, and then re-added just BREAK. C inherited break >from B. I haven't seen anyone say that that wasn't a mistake. >We just don't spend decades worrying about it. A minor historical quibble: BCPL, at the time of C's invention, did not have `ENDCASE`; that came later. We tend to forget that BCPL did not stop evolving after C's invention; in fact, it went on as a going concern for quite a few more years. From Dennis Ritchie's HOPL paper: |Not every difference between the BCPL language documented in |Richards's book [Richards 79] and B was deliberate; we started |from an earlier version of BCPL [Richards 67]. For example, the |`endcase` that escapes from a BCPL `switchon` statement was not |present in the language when we learned it in the 1960s, and so |the overloading of the `break` keyword to escape from the B and |C `switch` statement owes to divergent evolution rather than |conscious change. (https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html) Note this is the only place in that paper where Dennis Ritchie mentions `break`. Why was it overloaded for `switch`? He does not say, exactly, but he _does_ alude to space being a consideration for B, and some of the resulting syntactic quirks then escaping into C: |Storage limitations on the B compiler demanded a one-pass |technique in which output was generated as soon as possible, |and the syntactic redesign that made this possible was carried |forward into C. This is from a section discussing why C did not implement the, `valof`/`resultis` mechanism of BCPL: BCPL parsed the whole program into memory and operated on the parsed representation; B could not afford that luxury. Btw, one hypothesizes that some of the subsequent evolution of BCPL came from C influence; BCPL added the PL/1-style `/* ... */` comments, and it wouldn't surprise me if `ENDCASE` came from C's `break` inside of a `switch`, though I have no evidence of that. - Dan C.
Technical Details
Message-ID:
<11al2i7$gd2$1@reader2.panix.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11aj73v$c2u$1@reader2.panix.com> <11ajcv8$3u33s$1@dont-email.me> <11ajsfi$28f2$5@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!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Tue, 13 Oct 2026 10:52:55 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11al2i7$gd2$1@reader2.panix.com> References: <119qf6l$2rmg3$1@dont-email.me> <11aj73v$c2u$1@reader2.panix.com> <11ajcv8$3u33s$1@dont-email.me> <11ajsfi$28f2$5@kst.eternal-september.org> Injection-Date: Tue, 13 Oct 2026 10:52:55 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="16802"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross)