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

Mike Bolotski mikeb at ee.ubc.ca
Sat Sep 1 06:42:48 AEST 1990


In article <1990Aug30.164610.3519 at zoo.toronto.edu>, henry at zoo.toronto.edu (Henry Spencer) writes:
> In article <BURLEY.90Aug30030645 at world.std.com> burley at world.std.com (James C Burley) writes:
> >... how about this: allow ranges (and, perhaps, lists) on case statements.
> 
> Such a feature appeared in one draft of ANSI C, and disappeared in the
> next.  I believe the reason was the usual:  there was no implementation
> experience with it, and it was a minor convenience rather than a solution
> to a serious problem.

>From the G++ info file:

Switch Ranges
=============

A GNU C++ extension to the switch statement permits range specification
for case values.  For example, below is a concise way to print out
a function parameter's "character class:"

     print_char_class (char c) 
     {
       switch (c)
         {
         case 'a'..'z': printf ("lower case\n"); break;
         case 'A'..'Z': printf ("upper case\n"); break;
         case '0'..'9': printf ("digit\n"); break;
         default:       printf ("other\n");
         }
     }

Duplicate, overlapping case values and empty ranges are detected and
rejected by the compiler.

--
Mike Bolotski          VLSI Laboratory, Department of Electrical Engineering
mikeb at salmon.ee.ubc.ca University of British Columbia, Vancouver, Canada 



More information about the Comp.std.c mailing list