home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!agate!ucbvax!lrw.com!leichter
- From: leichter@lrw.com (Jerry Leichter)
- Newsgroups: comp.os.vms
- Subject: Re: problem report of toupper() in GCC 1.42 on VMS
- Message-ID: <9301251357.AA21625@uu3.psi.com>
- Date: 25 Jan 93 12:56:19 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Distribution: world
- Organization: The Internet
- Lines: 61
-
- After all the rambling discussion of what toupper() should do with characters
- that are not lower case letters, Arne Vajhxj finally asks the right question:
-
- What does the ANSI standard say about toupper ? [comments welcome]
-
- Here is the exact wording:
-
- 4.3.2.2 The toupper function
- Synopis
- #include <ctype.h>
- int toupper(int c);
-
- Description
- The toupper function converts a lower-case character to the
- corresponding upper-case character.
-
- Returns
- If the argument is a character for which islower is true and
- there is a corresponding character for which isupper is true,
- the toupper function returns the corresponding character;
- otherwise, the argument is returned unchanged.
-
- Hence: The GNU C definition is not ANSI compatible.
-
- The POSIX spec includes the toupper function by reference to the ANSI C spec,
- so GNU C isn't POSIX compatible either.
-
- The 4.2BSD documentation I've got doesn't even mention toupper. I don't have
- the appropriate System V documentation here - anyone?
-
- The original K&R mentions toupper but says only that "toupper(c) convert[s] c
- to upper case". The Second Edition of K&R is true to the ANSI C definition.
-
- >From the code Mr. Vajhxj pulled out of the DECStation C library:
-
- #if !defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
- #define _toupper(c) ((c)-'a'+'A')
- #endif
-
- It would see that XOPEN called for a _toupper macro that clobbered non-lower-
- case characters. Since Ultrix has historically been mainly BSD-compliant, my
- guess is that the "non-POSIX" arm of the conditional was meant to provide
- compatibility with BSD implementations, which probably had this style of
- _toupper macro, too.
-
- Aren't standards wonderful?
-
- Jaeschke's "Portability and the C Language", which tries to give you the most
- conservative, portable definitions, specifically says that anything that is
- not a lower-case letter is returned intact. But it then proceeds to mention
- _toupper as a macro form of toupper provided by some implementations: Where
- toupper must be "safe", even if defined as a macro (it only references its
- argument once), _toupper may not be (though it may be faster). Jaeschke gives
- no hint that toupper's and _toupper's semantics otherwise differ - but then
- proceeds to give a sample implementation:
-
- #define _toupper(c) ((c) + 'A' - 'a')
-
- Great, huh?
- -- Jerry
-
-