Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!mailrus!tut.cis.ohio-state.edu!rutgers!gatech!bbn!bbn.com!lpringle From: lpringle@bbn.com (Lewis G. Pringle) Newsgroups: comp.lang.c++ Subject: Re: goodbye cpp ??? Message-ID: <33528@bbn.COM> Date: 14 Dec 88 18:27:34 GMT References: <6590072@hplsla.HP.COM> <1106@etive.ed.ac.uk> Sender: news@bbn.COM Reply-To: lpringle@labs-n.bbn.com (Lewis G. Pringle) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 58 >The current definition of C++ can't do half the things that the CPP can. >For example, inline functions can't replace macros that have declarations >or constant expressions on their rhs. An example of the latter is: > >#define CTRL(x) (x - 0100) >... > case CTRL('A'): > >Not that I'd mind a bit more restriction on what the preprocessor could >do -- just as long as I can still do all the things *I* want (semi ;-). This example reminds me of a suggestion for an extention to C++. The problem with the above code is that switch statements require the cases to be integer constants - though there is really no good reason for this. All too often I have seen code like if (a == thing1) { } else if (a == thing2) { } ... where either a is not an inteer, or the things are not constant. Sometimes the == is replaced by a strcmp(). When c++ sees a switch statement, it could generate the skip-chain of if-then-elseifs from that, so long as the argument to the switch and the cases where all =='able. (As an optimization - of course - when the cases are all constant it could just output the C switch statement as-is.) For example, the cfront could translate switch (GetSomeStringFromSomeWhere) { case "Fred": { } break; case "Barny": { } break; } into the obvious if-then-else chain. NB: This example assumes an class String() with op== and String(char *) I guess there is one implicit assumtion in all of this, and that is that the case statement is clearer than the long list of if-then-elses, but I take that for granted. I also realize that this might be taken as a bit kitchen-sinky. Still, I think that it would make C++ an even-better C :-). Lewis. "OS/2: half an operating system for half a computer." In Real Life: Lewis Gordon Pringle Jr. Electronic Mail: lpringle@labs-n.bbn.com Phone: (617) 873-4433