Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: toupper(EOF) (was Re: Style) Message-ID: <380@lakart.UUCP> Date: 3 Jan 89 16:48:04 GMT References: <9256@smoke.BRL.MIL> Organization: Lakart Corporation, Newton, MA Lines: 41 From article <9256@smoke.BRL.MIL>, by gwyn@smoke.BRL.MIL (Doug Gwyn ): > In article <189@becker.UUCP> bdb@becker.UUCP (Bruce Becker) writes: >> It might be useful to add that testing for EOF is >> possible - this raises the question of its value. >> Ought it to be -1, or 0xFF, or what? I'm confused >> about what the value of "toupper(EOF)" should be... > > EOF is not required to be defined as -1, but that is really the > most practical choice in every environment I've seen. It must > NOT be the same as a possible character value, so 0xFF is wrong. > > I don't think EOF is supposed to be a valid argument for toupper(), > just for the is*() functions. I don't know about the rest of the world, but there are three classes of toupper() that I know about. 1. they correctly convert lower case letters, and are undefined for ANY OTHER VALUES. What this does with EOF will be undefined. 2. they convert lower case to upper, and leave ALL OTHER VALID characters alone; undefined otherwise. Since EOF (ipso facto) is not a valid character it is again undefined. 3. they convert lower case to upper and leave EVERYTHING else alone. In this environment toupper(EOF) == EOF. However, since portability requires that one assume 1., toupper(EOF) is non-portable, hence probably best left alone. If you DO want 3. try the following: int to_upper(c) int c; { return(islower(c) ? toupper(c) : c); } -- dg@lakart.UUCP - David Goodenough +---+ | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+