Proposed Enhancement to select/case (yes, I know...)

Dave Gillespie daveg at near.cs.caltech.edu
Wed Sep 5 10:56:16 AEST 1990


>>>>> On 1 Sep 90 22:43:36 GMT, henry at zoo.toronto.edu (Henry Spencer) said:

> In article <1990Aug31.134248 at ee.ubc.ca> mikeb at salmon.ee.ubc.ca writes:
>>         case 'A'..'Z': printf ("upper case\n"); break;

> Heh heh.  What does this do on an EBCDIC machine?  Not what you think!

Here's a solution:  In <ctype.h> define macros which expand to the
necessary case ranges and/or lists for various subsets of the target
character set:  Lowercase alpha, uppercase alpha, and digits.

A somewhat ugly but workable underlying case syntax would be, e.g.:
    case 'a'..z'; 'A'..'Z'; '_':  begin_c_identifier(); break;

One flaw with this is that isalpha() can be defined to be run-time
configurable for different national alphabets, but macros cannot.

Perhaps the "right" extension is to allow arbitrary predicates in
a case label ("case isalpha:"), but I can't think of a really nice
syntax for it, especially if you want to allow macros to be used as
the predicate.

								-- Dave
--
Dave Gillespie
  256-80 Caltech Pasadena CA USA 91125
  daveg at csvax.cs.caltech.edu, ...!cit-vax!daveg



More information about the Comp.std.c mailing list