Proposed Enhancement to select/case (yes, I know...)
Martin Fouts
fouts at bozeman.bozeman.ingr.UUCP
Fri Sep 14 01:49:35 AEST 1990
The debate over 'a'..'z' is silly. It is easy to define a portable
semantic which does what the programmer wants and which can be
compiled with any compiler on any machine. By specifying the semantic
to be any member of the set of integers which maps into the character
set (here enumerate a, b, c, etc).
The problem is hinted at by Doug Gwyn in his parenthetic comment
"(These are numbers, not characters!)" The portable solution is to
define behavior for characters, thus ending the debate.
Of course, there is no existing practice for characters as such in
either C or C++ (or many other languages) so it is probably not
appropriate for either the C or C++ standard groups to address the
problem.
The more general problem of ranges can also be discussed in the
context of enums. The following pseudo-C code is an example of a good
use of switch statement ranges in enum land
enum Piece (Empty, King, Queen, Rook, Knight, Bishop, Pawn, Invalid);
Piece square[HIGH][DEEP];
int x, y;
switch(square[x][y]) {
case Empty:
handle_empty();
break;
case King..Pawn:
check_attack(x,y);
break;
case Invalid:
fall_apart();
default:
die_badly();
}
is a sample of enumeration based ranges in switch statements which are
desirable and highly portable, and for which some existing practice
(gcc) can be used as an example.
Marty
--
Martin Fouts
UUCP: ...!pyramid!garth!fouts (or) uunet!ingr!apd!fouts
ARPA: apd!fouts at ingr.com
PHONE: (415) 852-2310 FAX: (415) 856-9224
MAIL: 2400 Geng Road, Palo Alto, CA, 94303
Moving to Montana; Goin' to be a Dental Floss Tycoon.
- Frank Zappa
More information about the Comp.std.c
mailing list