Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!uakari.primate.wisc.edu!unmvax!pprg.unm.edu!topgun!mustang!nntp-server.caltech.edu!seismo.gps.caltech.edu!bruce From: bruce@seismo.gps.caltech.edu (Bruce Worden) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <1990Oct18.182650.7188@nntp-server.caltech.edu> Date: 18 Oct 90 18:26:50 GMT References: <1990Oct17.170914.683@wpi.WPI.EDU> <11021@hubcap.clemson.edu> Sender: bruce@seismo.gps.caltech.edu (Bruce Worden) Organization: California Institute of Technology, CA Lines: 21 Nntp-Posting-Host: sis.gps.caltech.edu 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. And from what I remember from the `toupper()' and `tolower()' discussion here about three months ago, I think it was generally agreed that a macro that evaluates its argument three times must be used with great caution ( toupper(getchar()) can happen, e.g.), and that the simple subtraction ( ch-32 ) and comparisons ( ch<123, ch>96) are inherently non-portable. P.S. I, among others, missed the *duh = "hello"; bug. My apologies. -------------------------------------------------------------------------- C. Bruce Worden bruce@seismo.gps.caltech.edu 252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125