Symbols and integers are pretty closely related in C.
When you get a character from an input stream, it should be able to represent each individual character plus the end-of-file character.
This means that the char
type will not be large enough to use a wider type.
The justification document C99 says:
Since these functions are often used primarily as macros, their domain is limited to small positive integers represented in an unsigned char, plus an EOF value. EOF is traditionally -1, but can be any negative integer and therefore be different from any valid character code. Thus, these macros can be efficiently implemented using the argument as an index in a small array of attributes.
The standard itself says this:
The <ctype.h>
declares several functions useful for classifying and matching characters. In all cases, the argument is an int whose value must be represented as an unsigned char or equal to the value of the EOF macro. If the argument has any other value, the behavior is undefined.
source share