None of character type functions are required to handle EOF
, other than ignoring it (i.e. returning false). In fact, EOF marker is not even mentioned in <ctype.h>
header documentation.
The most likely reason for character classification function signatures to use int
in place of char
, signed or unsigned, is to avoid implementation-defined behavior in loops like this:
int c;
while ((c =getchar()) != EOF) {
if (islower(c)) {
...
} else if (isdigi(c)) {
...
}
}
This would compile and run with islower(char)
instead of islower(int)
, but the result would be implementation defined, which is not desirable under such basic circumstances. Essentially, int
in the signature of getchar
became "contagious," getting into signatures of functions only marginally related to it.