Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: towards a faster isdigit() Message-ID: <720@taumet.com> Date: 9 May 91 15:00:48 GMT References: <1991May8.030515.7004@twinsun.com> <1991May8.154453.4462@intellistor.com> Distribution: usa Organization: Taumetric Corporation, San Diego Lines: 29 wicklund@intellistor.com (Tom Wicklund) writes: >In <1991May8.030515.7004@twinsun.com> eggert@twinsun.com (Paul Eggert) writes: >>Why not use the following implementation instead? >> #define isdigit(c) ((unsigned)((c)-'0') < 10) >Two portability problems -- >1) Numeric digits aren't adjacent character codes in all character >sets ... ANSI C requires that '0' thru '9' be contiguous and in that order. >2) The (unsigned) cast may not work ANSI C requires that the unsigned cast work as well-defined modulo arithmetic, so that any negative value cast to unsigned looks like a large positive value. >Note the first "traditional" implementation isn't completely portable >either since it assumes that EOF is -1, not necessarily true. EOF and the functions are supplied as part of the C library. They must all be consistent. Any library for which EOF is not -1 would not use _ctype[(c)+1] to index an array. We are talking about the library implementation, not arbitrary user code. -- Steve Clamage, TauMetric Corp, steve@taumet.com