Path: utzoo!utgpu!attcan!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: getch() and getche() in MSC 4.0 Message-ID: <561@quintus.UUCP> Date: 22 Oct 88 03:32:29 GMT References: <10508@dartvax.Dartmouth.EDU> <7594@bloom-beacon.MIT.EDU> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 26 In article <7594@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes: >This is a snide, whiney "I told you so" to the efficiency addicts >and macro panderers out there. > > #define _toupper(c) ((c) - ('a' - 'A')) > #define toupper(c) (islower(c) ? _toupper(c) : (c)) > >If it is desirable for toupper to work correctly on characters >that are nonalphabetic or already upper-case (I believe this >property is called "idempotence," and as I said, it is a laudable >goal), then the macro implementation has to be sacrificed, and >toupper() made a proper function. This conclusion does not follow. *THAT* version of toupper() has to go, but you can still usefully use a macro. extern char _utab[]; #define toupper(c) _utab[(c) & 255] Merits: (1) single evaluation (2) usually faster than a function call (3) works nicely with EBCDIC or ISO 8859, not just ASCII This is a good way of turning any function-from-characters into a macro: compute all the function values when your program starts and store them in an array. (Look at the is() macros in /usr/include/ctype.h .)