Subject: Re: isxxx() and toupper() usage changes
To: Jason Thorpe <thorpej@shagadelic.org>
From: David Laight <david@l8s.co.uk>
List: tech-userlevel
Date: 10/27/2004 22:00:31
On Wed, Oct 27, 2004 at 01:31:47PM -0700, Jason Thorpe wrote:
> 
> On Oct 27, 2004, at 12:59 PM, David Laight wrote:
> 
> >Fix a load of international alphabet problems with isxxx() and 
> >toupper()
> >Change isspace(*char_ptr) to isspace(*char_ptr & 0xff) so that the 
> >correct
> >piece of memory is looked at for the bit mask.
> >gcc optimises out the '& 0xff' (on i386 at least).
> >Fixes problems found by gcc when the splurious (int) cast is removed
> >from the #defines in ctype.h
> 
> Uh... the right piece of memory would be looked at anyway because of 
> the promotion rules, right?
> 
> I just don't see how this change is even remotely "correct".  Is this 
> actually recommended usage of these functions??

Yes, absolutely!!!
From www.opengroup.org/onlinepubs/009695399/functions/isdigit.html

The c argument is an int, the value of which the application shall ensure is
a character representable as an unsigned char or equal to the value of the
macro EOF.  If the argument has any other value, the behavior is undefined.

So if you have a signed char you have to do something to it in order
not to get the 'undefined' behaviour.

	David

-- 
David Laight: david@l8s.co.uk