Path: utzoo!attcan!uunet!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!ncar!boulder!pikes!aspen.craycos.com!jrbd From: jrbd@craycos.com (James Davies) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <1990Oct22.203452.581@craycos.com> Date: 22 Oct 90 20:34:52 GMT References: <1990Oct17.170914.683@wpi.WPI.EDU> <11021@hubcap.clemson.edu> <1990Oct18.182650.7188@nntp-server.caltech.edu> Organization: Cray Computer Corporation Lines: 28 In article <1990Oct18.182650.7188@nntp-server.caltech.edu> bruce@seismo.gps.caltech.edu (Bruce Worden) writes: >svissag@hubcap.clemson.edu (Steve L Vissage II) writes: >>From article <1990Oct17.170914.683@wpi.WPI.EDU>, by profesor@wpi.WPI.EDU (Matthew E Cross): >>> Nope, won't work - the return value of 'toupper' is undefined if the input is >>> not a lowercase character. >> >>So define your own toupper() macro. That's what I did. >>#define toupper(ch) ((ch<123 && ch>96) ? ch-32 : ch) >> [ ... ] > >I wouldn't recommend defining a macro with the same name as a library >function. I would certainly second that notion, and go further to say that the average programmer also shouldn't be messing around with system includes at all. I once sent out some C code for a C program to a guy who had modified his C compiler's definition of "isalpha" so that it used a table lookup rather than the supplied library function (for "efficiency", of course). He lifted the macro definitions for his new isalpha from another compiler and then made up the table by himself. Trouble was, he had an off-by-one error in the table, so that it considered "Z" to not be a letter. After about two hours on the phone with him running his debugger and me coaching, we found the problem. (Of course, he didn't tell me about this in advance, I had to infer it from my program's behaviour). I suspect his toalpha macro will make up the time we wasted sometime in the next century...