Programming and international chara

mcdaniel at uicsrd.csrd.uiuc.edu mcdaniel at uicsrd.csrd.uiuc.edu
Thu Nov 10 16:10:00 AEST 1988


Written  8:30 pm  Nov  7, 1988 by ok at quintus.uucp in comp.lang.c:
> In article <44200016 at uicsrd.csrd.uiuc.edu>
> mcdaniel at uicsrd.csrd.uiuc.edu writes: 
>> One possible macro implementation is:
>>	#define iscntrl(c)	( (c) >= 0 && (c) <= 037 )
>
> A reasonably well-known hack, where L and U are constant integer expressions,
> is	#define inrange(x,L,U) ((unsigned)((x)-(L)) <= (unsigned)((U)-(L)))
> It has the virtue that x is evaluated only once.

Migod, it's even dpANS portable, for ints x, L, and U, if no overflow.
Also: suppose L > U.  Let us define the range "L .. U" to be L up to
INT_MAX, then wrapping around to INT_MIN, and then up to U.  This
macro does the "wrapped" test properly: it tests for x being in L ..
INT_MAX or INT_MIN .. U.  In other words, if L > U, it tests for x NOT
in L .. U.  Neat hack!

> In this case:
>	*define iscntrl(c) ((unsigned)(c) < 32)
> I say "*define" because the usual definition of iscntrl() for ASCII
> includes DEL as one of the cntrl characters.

Of course.  The original poster (not "ok at quintus", the other one
quoted above) was a real bozo.  One of those jerks who thinks he's a
real know-it-all net.god.  He just spouted off the very first #define
that came to mind, without stopping to think whether he might be WRONG
(Kernighan forbid).  He should be ashamed of himself for spreading
such obviously broken code on a public net.

-- 
Tim, the Bizarre and Oddly-Dressed Enchanter
Center for Supercomputing Research and Development
at the University of Illinoid at Urbana-Champaign

Internet, BITNET:  mcdaniel at uicsrd.csrd.uiuc.edu
UUCP:    {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
ARPANET: mcdaniel%uicsrd at uxc.cso.uiuc.edu
CSNET:   mcdaniel%uicsrd at uiuc.csnet
DECnet?: GARCON::"mcdaniel at uicsrd.csrd.uiuc.edu"



More information about the Comp.lang.c mailing list