Return to BSD News archive
Path: sserve!newshost.anu.edu.au!munnari.oz.au!mel.dit.csiro.au!its.csiro.au!dmssyd.syd.dms.CSIRO.AU!metro!sequoia!ultima!kralizec.zeta.org.au!godzilla.zeta.org.au!not-for-mail
From: bde@kralizec.zeta.org.au (Bruce Evans)
Newsgroups: comp.os.386bsd.bugs
Subject: Re: ctype.h Bug & Fix
Date: 18 Jul 1993 21:06:51 -0000
Organization: Kralizec Dialup Unix Sydney: +61-2-837-1183 V.42bis
Lines: 32
Message-ID: <22ce1bINN21k@godzilla.zeta.org.au>
References: <CA69Fo.Lwv@bi-link.owl.de> <CA9B9F.Gx5@sugar.NeoSoft.COM>
NNTP-Posting-Host: godzilla.zeta.org.au
peter@NeoSoft.com (Peter da Silva) writes:
>In article <CA69Fo.Lwv@bi-link.owl.de> martin@bi-link.owl.de (Martin Husemann) writes:
>> #define toupper(c) (islower(c)?((c) - 'a' + 'A'):(c))
>> #define tolower(c) (isupper(c)?((c) - 'A' + 'a'):(c))
>Be nicer to make it 2-step:
>> #define _toupper(c) ((c) - 'a' + 'A')
>> #define _tolower(c) ((c) - 'A' + 'a')
>> #define toupper(c) (islower(c)?_toupper(c):(c))
>> #define tolower(c) (isupper(c)?_tolower(c):(c))
Be nicer to make it correct:
(1) Side effects are not permitted.
(2) Prototypes are required for the functions behind these macros.
(3) _tolower may not be used in a macro because it pollutes the application
namespace (auto int _tolower; ...).
(4) _ctype may not be used in a macro because it pollutes the application
namespace (auto int _ctype; ...). _ctype is now used for most of the
other ctype macros.
Might be nice to make it faster:
#define toupper(c) __toupper_table[(c) + 128]; /* -128 <= c < 255 */
This handles negative characters to support the common (broken) idiom
topupper(*pointer_to_maybe_signed_char). The argument must be representable
as an unsigned char, or EOF.
--
Bruce Evans bde@kralizec.zeta.org.au