toupper(EOF) (was Re: Style)
David Goodenough
dg at lakart.UUCP
Wed Jan 4 02:48:04 AEST 1989
>From article <9256 at smoke.BRL.MIL>, by gwyn at smoke.BRL.MIL (Doug Gwyn ):
> In article <189 at becker.UUCP> bdb at 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 at lakart.UUCP - David Goodenough +---+
| +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.lang.c
mailing list