Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!eru!luth!sunic!mcsun!ukc!stc!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.lang.c Subject: Re: isascii (was: Another pitfall. Signed chars and ctype.h) Message-ID: <1220@root44.co.uk> Date: 14 Feb 90 12:25:14 GMT References: <1990Feb12.043324.5259@sq.sq.com> Reply-To: gwc@root.co.uk (Geoff Clare) Organization: UniSoft Ltd, London, England Lines: 33 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) 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@root.co.uk (Dumb mailers: ...!uunet!root.co.uk!gwc) Tel: +44-1-315-6600 (from 6th May 1990): +44-71-315-6600