isascii (was: Another pitfall. Signed chars and ctype.h)

Bruce Evans evans at ditsyda.oz
Thu Feb 15 16:02:14 AEST 1990


In article <1990Feb12.043324.5259 at sq.sq.com> msb at sq.com (Mark Brader) writes:
*If the code has to run on ANSI and non-ANSI C's, I'd prefer:
*
*	#include <stdio.h>
*	#include <ctype.h>
*
*	#ifndef isascii		/* oh, must be ANSI C */
*	#define isascii(x) (((x) >= 0 && (x) < UCHAR_MAX) || (x) == EOF))
*	#endif
*
*and then
*	isascii(*s) && isdigit(*s)

Why doesn't ANSI C guarantee isdigit() (etc.) on *all* characters? The usual
implementation would be to move the base of the ctype array from -1
(EOF) back to -128 (SCHAR_MIN).

Then you can define isascii(x) to be 1 in the above, and not have to worry
about side affects. You still have to watch out for isdigit() on non-chars.
-- 
Bruce Evans		evans at ditsyda.oz.au



More information about the Comp.lang.c mailing list