home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / os2 / programm / 4438 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  1.6 KB

  1. Path: sparky!uunet!convex!darwin.sura.net!europa.asd.contel.com!emory!swrinde!news.dell.com!milano!shrike!ut-emx!emx.utexas.edu!plyon
  2. From: plyon@emx.cc.utexas.edu (Paul Lyon)
  3. Newsgroups: comp.os.os2.programmer
  4. Subject: Re: gcc/2 libc: toupper()/tolower() broken in ctype.h
  5. Message-ID: <PLYON.92Aug23234316@emx.cc.utexas.edu>
  6. Date: 24 Aug 92 04:43:16 GMT
  7. References: <PLYON.92Aug23194717@emx.cc.utexas.edu>
  8. Sender: news@ut-emx.uucp
  9. Distribution: comp.os.os2.programmer
  10. Organization: The University of Texas at Austin
  11. Lines: 24
  12. In-reply-to: plyon@emx.cc.utexas.edu's message of 24 Aug 92 00:47:17 GMT
  13.  
  14. This is a followup to my earlier post about fixing the toupper() and
  15. tolower() macros in the ctype.h currently in the gcc/2 distribution.
  16.  
  17. I think I must of been half-asleep when I wrote it :-( My suggested
  18. fix will not, of course, work if the argument expression has
  19. side-effects. For example, toupper(*p++) will lose, since the pointer
  20. will be incremented twice.
  21.  
  22. In any case Eberhard Mattes already put a better fix in emx, namely
  23. this: 
  24.  
  25. static __inline__ int _toupper (int c) { return (c-'a'+'A'); }
  26. static __inline__ int _tolower (int c) { return (c-'A'+'a'); }
  27. static __inline__ int toupper(int c) {return (islower(c) ? _toupper(c) : c);}
  28. static __inline__ int tolower(int c) {return (isupper(c) ? _tolower(c) : c);}
  29.  
  30. I only thought to check the emx ctype.h _after_ I wrote the preceeding
  31. note :-( :-(. Being proper functions, these will not be vulnerable to
  32. expressions with side effects, and the compiler will also type check
  33. your argument and return value while it is at it.
  34.  
  35. With reddened face...
  36.  
  37. Paul Lyon
  38.