Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!uflorida!ukma!cwjcc!hal!nic.MR.NET!tank!uxc!uxc.cso.uiuc.edu!uxg.cso.uiuc.edu!uicsrd.csrd.uiuc.edu!mcdaniel From: mcdaniel@uicsrd.csrd.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Programming and international chara Message-ID: <44200020@uicsrd.csrd.uiuc.edu> Date: 10 Nov 88 06:10:00 GMT References: <532@krafla.rhi.hi.is> Lines: 40 Nf-ID: #R:krafla.rhi.hi.is:532:uicsrd.csrd.uiuc.edu:44200020:000:1764 Nf-From: uicsrd.csrd.uiuc.edu!mcdaniel Nov 10 00:10:00 1988 Written 8:30 pm Nov 7, 1988 by ok@quintus.uucp in comp.lang.c: > In article <44200016@uicsrd.csrd.uiuc.edu> > mcdaniel@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@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@uicsrd.csrd.uiuc.edu UUCP: {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel ARPANET: mcdaniel%uicsrd@uxc.cso.uiuc.edu CSNET: mcdaniel%uicsrd@uiuc.csnet DECnet?: GARCON::"mcdaniel@uicsrd.csrd.uiuc.edu"