Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!emory!audfax!arnold From: arnold@audiofax.com (Arnold Robbins) Newsgroups: comp.lang.c Subject: Re: _tolower and _toupper macros Message-ID: <248@audfax.audiofax.com> Date: 30 Jul 90 14:27:45 GMT References: <2891@dftsrv.gsfc.nasa.gov> <1990Jul26.100721.14628@warwick.ac.uk> <246@audfax.audiofax.com> <1990Jul28.193255.16540@laguna.ccsf.caltech.edu> Organization: AudioFAX Inc., Atlanta Lines: 47 >In article <246@audfax.audiofax.com> arnold@audiofax.com (Arnold Robbins) writes: >>I guess tolower() and toupper() remain real functions in V.3.2 in case >>anyone takes their address; I can't see any other reason to not have them >>be macros identical to their _to* counterparts. In article <1990Jul28.193255.16540@laguna.ccsf.caltech.edu> bruce@seismo.gps.caltech.edu (Bruce Worden) writes: >I don't believe that this is the reason for implementing to*() as functions. >The most important reason is so that these functions can work on >non-US-ascii character sets (i.e. they will continue to function correctly >after a call to setlocale() which changes the LC_CTYPE locale.) >Another important reason is to avoid multiple evaluations of the argument >as has been discussed elsewhere. On the surface this makes sense, but it's still possible to write a macro that will work when setlocale changes the locale and only evaluates its argument once. Like so: In ctype.h: extern char *_casemap; #define tolower(c) (_casemap[c]) #define toupper(c) (_casemap[c]) In setlocale.c: static char casemap_french[256] = { .... }; static char casemap_spanish[256] = { .... }; static char casemap_c_locale[256] = { .... }; .... char *_casemap = casemap_c_locale; setlocale(int locale) /* or whatever arg it takes, i don't know */ { if (locale == france) _casemap = casemap_french; else if (locale == spain) _casemap = casemap_spanish; else ..... } Simple enough, no? (Yes, I know setlocale has to do lots of other stuff. This is an example for the sake of discussion, ok?) -- Arnold Robbins AudioFAX, Inc. | Laundry increases 2000 Powers Ferry Road, #220 / Marietta, GA. 30067 | exponentially in the INTERNET: arnold@audiofax.com Phone: +1 404 933 7600 | number of children. UUCP: emory!audfax!arnold Fax: +1 404 933 7606 | -- Miriam Robbins