Newsgroups: comp.lang.c
Path: utzoo!sq!msb
From: msb@sq.sq.com (Mark Brader)
Subject: isascii (was: Another pitfall.  Signed chars and ctype.h)
Message-ID: <1990Feb12.043324.5259@sq.sq.com>
Summary: #define isascii
Reply-To: msb@sq.com (Mark Brader)
Organization: SoftQuad Inc., Toronto
References: <Cuunry2@cs.psu.edu>
Date: Mon, 12 Feb 90 04:33:24 GMT

> >	isascii(*s) && isdigit(*s)
> 
> According to _Standard C_ ... there is no "isascii".  And "isdigit" etc.
> take an int in the set (EOF, 0..UCHAR_MAX) ...

> So, to write ANSI conformant C you must always say something like
> 	isdigit((unsigned char) *s)

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)

The X3J11 people did not put isascii() in ANSI C because of the "ascii"
part of the name.  Correctly, they did not want to make any part of the
C Standard ASCII-dependent.  I suggested that isascii() be guaranteed
merely to have semantics similar to the above #define and the name kept
as a historical artifact, but they didn't buy it.

To keep this article short, I won't discuss making it work when the
argument has side-effects (as in isascii (*p++)).

-- 
Mark Brader		    At any rate, C++ != C.  Actually, the value of the
SoftQuad Inc., Toronto	    expression "C++ != C" is implementation-defined.
utzoo!sq!msb, msb@sq.com				-- Peter da Silva

This article is in the public domain.
