Re: Patch for isdigit/isalpha/etc. macro arguments

DJ Delorie
2007-04-09T13:43:00Z

> The value of '\377' is implementation-defined.

Not in the context of fgetc or <ctype.h> (the places where ambiguity
exists), it isn't (emphasis mine):

"If the end-of-file indicator for the input stream pointed to by
stream is not set and a next character is present, the fgetc
function obtains that character as an UNSIGNED CHAR converted to an
int and advances the associated file position indicator for the
stream (if defined)."

"The header <ctype.h> declares several functions useful for
classifying and mapping characters. In all cases the argument is an
int, the value of which shall be representable as an UNSIGNED CHAR
or shall equal the value of the macro EOF. If the argument has any
other value, the behavior is undefined.

It is, unfortunately, up to the programmer to deal with other sources
of character data which may be sign extended, and provide the ctype
macros with the input range they're expecting.

In the case of casts from char* strings, the programmer should:

isalpha((int)(unsigned char)(*s))

Messy, but pedantic. The cast to int may be optional.