Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!uokmax!munnari.oz.au!cluster!metro!natmlab.dap.csiro.au!ditsyda!evans From: evans@ditsyda.oz (Bruce Evans) Newsgroups: comp.lang.c Subject: Re: isascii (was: Another pitfall. Signed chars and ctype.h) Message-ID: <2448@ditsyda.oz> Date: 15 Feb 90 05:02:14 GMT References: <1990Feb12.043324.5259@sq.sq.com> Reply-To: evans@ditsyda.oz (Bruce Evans) Organization: CSIRO DIT Sydney, Australia Lines: 21 In article <1990Feb12.043324.5259@sq.sq.com> msb@sq.com (Mark Brader) writes: *If the code has to run on ANSI and non-ANSI C's, I'd prefer: * * #include * #include * * #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@ditsyda.oz.au