The various is... functions (e.g. isalpha, isdigit) in ctype.h aren’t entirely predictable. They take int arguments but expect character values in the unsigned char range, so on a platform where char is signed, passing a char value directly could lead to undesirable sign extension. I believe that the typical approach to handling this is to explicitly cast to an unsigned char first.
Okay, but what is the proper, portable way to deal with the various isw... functions in wctype.h? wchar_t, like char, also may be signed or unsigned, but because wchar_t is itself a typedef, a typename of unsigned wchar_t is illegal.
Upon re-reading the ISO C99 specification regarding
wctype.h, it states:Contrast this with the corresponding note for
ctype.h:(emphasis mine)
I think that it’s also worth understanding the motivation for why the
ctype.hfunctions requireunsigned charrepresentations. The standard requires thatEOFbe a negativeint(§7.19.1/3), so thectype.hfunctions useunsigned charrepresentations to (try to) avoid potential ambiguity.In contrast, that motivation doesn’t exist for
wctype.hfunctions. The standard makes no such requirement ofWEOF, elaborated by footnote 270:because
WEOFis already guaranteed to not conflict with any character represented bywchar_t(§7.24.1/3).Therefore the
wctype.hfunctions don’t have or need any of the unsigned nonsense, andwchar_tvalues can be passed to them directly.