Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!amdcad!lll-crg!gymble!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: Unchecked Switch Statement Message-ID: <225@umcp-cs.UUCP> Date: Wed, 12-Mar-86 17:06:31 EST Article-I.D.: umcp-cs.225 Posted: Wed Mar 12 17:06:31 1986 Date-Received: Fri, 14-Mar-86 07:28:56 EST References: <1706@brl-smoke.ARPA> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 44 In article <1706@brl-smoke.ARPA> dietz%slb-doll.csnet@CSNET-RELAY.ARPA writes: >There seems to be an philosophical difference in C between array >accesses and switch statements. ... A more consistent definition >would have the compiler generate code that checks for an out-of-bounds >switch expression only when a default label is present. I think the way you stated this is unclear; I am going to guess that by this you mean writing (e.g.) switch (exp) { case c1: ...; case c2: ...; } nextstmt; would give undefined results if `exp' were not `c1' or `c2': a compiler might give a run-time error, or might not; and execution might fall through to `nextstmt', or stop, or even just go someplace at random, as though switch were internally implemented by that particular compiler as pc <- switchaddrs[exp] Given the assumption that this is what you meant, I would agree if C allowed arbitrary array arrangements (e.g., sparse arrays). In this case, arrays would be arrays of data, and switches would be arrays of code. Imagine: var = array[ index; default: printf("%d: out of bounds array index\n", index); exit(1); ]; (Ok, enough wild and crazy ideas.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu