Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!labrea!decwrl!pyramid!prls!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: comp.lang.c Subject: Switch statements Message-ID: <2347@mmintl.UUCP> Date: Wed, 31-Dec-69 18:59:59 EDT Article-I.D.: mmintl.2347 Posted: Wed Dec 31 18:59:59 1969 Date-Received: Fri, 11-Sep-87 00:38:05 EDT References: <855@tjalk.cs.vu.nl> <2683@hoptoad.uucp> <916@haddock.ISC.COM> <929@haddock.ISC.COM> <867@mcgill-vision.UUCP> <1022@haddock.ISC.COM> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT. Lines: 40 In article <1022@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >In other words, "case CR, LF:" would have the new semantics, whereas >"case (CR, LF):" would be equivalent to "case LF:". This is no more >problematic than the current overloading of comma for function calls. I always thought of the use of the comma to separate function arguments as the primary use, and the "ignore the first argument" operator as being the overloading. All in all, not one of the better features of the language. (The overloading, that is; I do *not* want to reopen the debate about the value of that operator.) One other possibility would be to use a semicolon: "case CR; LF:". This would not cause any direct parsing problems, but might be confusing for compiler error recovery routines and people. -------------------------------------------------------------------- One occasional problem with C, which does not fit with the overall language philosophy, is that a range check is always[1] implicit in a switch statement. If the statement happens to be at a key place in the code, a not unusual occurrence, this can add significantly to running time. Does anyone have any suggestions for a good syntax to indicate to the compiler that this check is not desired; that if the discriminant is not one of the specified cases, the result of the switch is to be undefined? I am a little surprised that K&R didn't make that the result of executing a switch statement with no 'default:' label. (I should note that I think the current definition is better, and would dislike that if it were the way switch statements were defined.) It is, in any case, too late for that interpretation now. On the other hand, I can't think of any way to specify this which doesn't make me sick. [1] Well, almost always. It is possible that the discriminant is pulled from a character or a bit field, and that all possibilities are explicitly covered; but this is an exceptional case. I doubt that any compiler checks for it. -- Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108