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

Geoff Clare gwc at root.co.uk
Wed Feb 14 23:25: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)

Sorry, that won't work on the many systems which have an ANSI-type
isdigit() AND a normal isascii().  This includes all X/Open Portability
Guide 3 compliant systems.

Also the assumption that isascii being undefined implies ANSI C is bogus.
A definition of isascii() could have been enabled by a feature test macro.

I believe the only way to cope with all variants of ctype.h macros, is
to have a user-supplied configuration parameter.  E.g.

#ifdef OLD_STYLE_CTYPE
#define ISDIGIT(x)	(isascii(x) && isdigit(x))
#else
#define ISDIGIT(x)	isdigit(x)
#endif

-- 
Geoff Clare, UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH
gwc at root.co.uk  (Dumb mailers: ...!uunet!root.co.uk!gwc)  Tel: +44-1-315-6600
                                         (from 6th May 1990): +44-71-315-6600



More information about the Comp.lang.c mailing list