home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 21941 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  2.6 KB

  1. Path: sparky!uunet!stanford.edu!agate!ucbvax!lrw.com!leichter
  2. From: leichter@lrw.com (Jerry Leichter)
  3. Newsgroups: comp.os.vms
  4. Subject: Re: problem report of toupper() in GCC 1.42 on VMS
  5. Message-ID: <9301251357.AA21625@uu3.psi.com>
  6. Date: 25 Jan 93 12:56:19 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: world
  9. Organization: The Internet
  10. Lines: 61
  11.  
  12. After all the rambling discussion of what toupper() should do with characters
  13. that are not lower case letters, Arne Vajhxj finally asks the right question:
  14.  
  15.     What does the ANSI standard say about toupper ? [comments welcome]
  16.  
  17. Here is the exact wording:
  18.  
  19.     4.3.2.2 The toupper function
  20.     Synopis
  21.         #include <ctype.h>
  22.         int toupper(int c);
  23.  
  24.     Description
  25.         The toupper function converts a lower-case character to the
  26.         corresponding upper-case character.
  27.  
  28.     Returns
  29.         If the argument is a character for which islower is true and
  30.         there is a corresponding character for which isupper is true,
  31.         the toupper function returns the corresponding character;
  32.         otherwise, the argument is returned unchanged.
  33.  
  34. Hence:  The GNU C definition is not ANSI compatible.
  35.  
  36. The POSIX spec includes the toupper function by reference to the ANSI C spec,
  37. so GNU C isn't POSIX compatible either.
  38.  
  39. The 4.2BSD documentation I've got doesn't even mention toupper.  I don't have
  40. the appropriate System V documentation here - anyone?
  41.  
  42. The original K&R mentions toupper but says only that "toupper(c) convert[s] c
  43. to upper case".  The Second Edition of K&R is true to the ANSI C definition.
  44.  
  45. >From the code Mr. Vajhxj pulled out of the DECStation C library:
  46.  
  47. #if !defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
  48. #define _toupper(c)    ((c)-'a'+'A')
  49. #endif
  50.  
  51. It would see that XOPEN called for a _toupper macro that clobbered non-lower-
  52. case characters.  Since Ultrix has historically been mainly BSD-compliant, my
  53. guess is that the "non-POSIX" arm of the conditional was meant to provide
  54. compatibility with BSD implementations, which probably had this style of
  55. _toupper macro, too.
  56.  
  57. Aren't standards wonderful?
  58.  
  59. Jaeschke's "Portability and the C Language", which tries to give you the most
  60. conservative, portable definitions, specifically says that anything that is
  61. not a lower-case letter is returned intact.  But it then proceeds to mention
  62. _toupper as a macro form of toupper provided by some implementations:  Where
  63. toupper must be "safe", even if defined as a macro (it only references its
  64. argument once), _toupper may not be (though it may be faster).  Jaeschke gives
  65. no hint that toupper's and _toupper's semantics otherwise differ - but then
  66. proceeds to give a sample implementation:
  67.  
  68.     #define _toupper(c) ((c) + 'A' - 'a')
  69.  
  70. Great, huh?
  71.                             -- Jerry
  72.  
  73.