🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1693

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

#1693
From: Martin Fouts
Date: Thu, 13 Sep 1990 15:49
53 lines
2355 bytes
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@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
Technical Details
Message-ID: <740@garth.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!uw-beaver!Teknowledge.COM!unix!garth!fouts@bozeman.bozeman.ingr.UUCP (Martin Fouts)
References: <1990Aug30.164610.3519@zoo.toronto.edu> <13714@smoke.BRL.MIL> <MEISSNER.90Aug31102441@osf.osf.org> <13719@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!uw-beaver!Teknowledge.COM!unix!garth!fouts@bozeman.bozeman.ingr.UUCP (Martin Fouts)
From: fouts@bozeman.bozeman.ingr.UUCP (Martin Fouts)
Newsgroups: comp.std.c
Subject: Re: Proposed Enhancement to select/case (yes, I know...)
Message-ID: <740@garth.UUCP>
Date: 13 Sep 90 15:49:35 GMT
References: <1990Aug30.164610.3519@zoo.toronto.edu> <13714@smoke.BRL.MIL> <MEISSNER.90Aug31102441@osf.osf.org> <13719@smoke.BRL.MIL>
Sender: fouts@garth.UUCP
Organization: INTERGRAPH (APD) -- Palo Alto, CA
Lines: 53
In-reply-to: gwyn@smoke.BRL.MIL's message of 2 Sep 90 02:27:34 GMT