Another pitfall. Signed chars and ctype.h.

Felix Lee flee at shire.cs.psu.edu
Thu Feb 8 09:15:50 AEST 1990


If you have "char * s;" you cannot say something like "isdigit(*s)" if
you want to be 8-bit clean.  "isdigit" etc. take an (int) in the range
[-1, UCHAR_MAX].

You have to say "isdigit((unsigned char) *s)".  Or you could declare
"unsigned char * s;" instead, but this is inconvenient since (char *)
isn't compatible with (unsigned char *).

This is only if your (char) is signed, but if you want to write
portably you shouldn't assume unsignedness of (char).
--
Felix Lee	flee at shire.cs.psu.edu	*!psuvax1!flee



More information about the Comp.lang.c mailing list