Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!sri-unix!sri-spam!ames!ucbcad!ucbvax!decvax!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Case ranges (was: goto's and switch statements) Message-ID: <972@haddock.ISC.COM> Date: Wed, 31-Dec-69 18:59:59 EDT Article-I.D.: haddock.972 Posted: Wed Dec 31 18:59:59 1969 Date-Received: Sat, 22-Aug-87 04:21:42 EDT References: <855@tjalk.cs.vu.nl> <2683@hoptoad.uucp> <916@haddock.ISC.COM> <298@auvax.UUCP> <10265@orchid.waterloo.edu> <6289@brl-smoke.ARPA> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 28 In article <6289@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <10265@orchid.waterloo.edu> rbutterworth@orchid.waterloo.edu (Ray Butterworth) writes: >> case 'a' :: 'z' : > >There's another serious problem underlying all these suggestions; >namely, that "a through z" has a well-defined meaning. Let's separate the two issues. As far as C's switch statement is concerned, the proposed notation *does* have a well-defined meaning, namely the set of all integers inclusively between the values for 'a' and 'z'. This is the same set matched by "if (c >= 'a' && c <= 'z')". This is as it should be. If, however, the user intended to match the set of all lowercase letters, then neither notation gives the correct answer outside the English/ASCII locale. Thus one should write "if (islower(c))", or in the proposed switch extension, "case ISLOWER:", where "ISLOWER" is defined in some header file. If the set to be matched is not determined at compile-time, then one should definitely use the "if" statement. I do not believe "switch" should be enhanced to match non-constant values. Now, if the only use for case ranges were to implement character typing, I'd say forget it, use the ctype functions. There are other uses; unfortunately, most of them are too application-specific to make good examples. Thus, each time this proposal comes up, it uses something like "'a'::'z'" to illustrate the concept, which immediately gets shot down as ASCII- or English-chauvinism. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint