Subject: Re: bin/21645: Localized comments and indent(1)
To: David Laight <email@example.com>
From: Richard Earnshaw <firstname.lastname@example.org>
Date: 06/25/2003 14:33:11
> On Wed, Jun 18, 2003 at 05:52:52PM +0300, Mishka wrote:
> > David Laight <email@example.com> wrote:
> > >
> > > The (int) cast only gets rid of a warning genberated by some compilers.
> > >
> > > The problem is that if 'c' is a signed char, then it is promoted to
> > > a signed integer using by preserving the sign. This does not DTRT
> > > for any of the isXXX() functions.
> > I'll see now. IYSS, how about (int)((unsigned char)c)?
> > So, the ctype convertion inside isXXXX() functions will looks like:
> > #define isXXXX(c) ((int)((_ctype_ + 1)[(int)((unsigned char)(c))] & (CTYPE_FLAGS)))
> > This causes the index [(int)((unsigned char)(c))] will always return
> > a positive value, even in signed int.
> No, you can't do that either (I think someone else said so in another
> thread), the domain of the isxxx() functions includes EOF (-1).
> So isupper(-1) is valid and, in this implementation, indexes the first
> item of the _ctype_ array.
Indeed. Actually, the fact that isXXX are usually macros makes no
difference -- if you pass a signed char to an isXXX function you'll get
the wrong results as well, because these functions take an int argument
and promotion of signed char to int will sign-extend. Conclusion - don't
pass char types to isXXX.