Is there a good example of how toupper() works?

James Davies jrbd at craycos.com
Tue Oct 23 06:34:52 AEST 1990


In article <1990Oct18.182650.7188 at nntp-server.caltech.edu> bruce at seismo.gps.caltech.edu (Bruce Worden) writes:
>svissag at hubcap.clemson.edu (Steve L Vissage II) writes:
>>From article <1990Oct17.170914.683 at wpi.WPI.EDU>, by profesor at 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...



More information about the Comp.lang.c mailing list