On Friday 28 December 2007 22:09:53 Thorsten Haude wrote:
> * Tony Balinski wrote (2007-09-07 18:04):
> >Another thing is the expression isalnum((int)*name). If char is
> >signed (I think it is/was(?) with Sun's compiler), this can cause
> >problems, especially with the old-fashioned macro implementation of
> >ctype.h. Better to use isalnum((unsigned char)*name) instead to be
> >explicit.
>
> Interesting, my book clearly calls for an int for ISO C. Why would the
> cast be a problem in this case?

plain char is signed (at least in gcc) on solaris. Casting to int causes sign 
extension. Which means that the character 'æ' (230) will be treated as a 
negative number indexing into the bogus area in ctype's tables (see post 
2007-10-15 19:12). So a cast to int causes problems. The solaris-compatible 
cast is
        isalnum((unsigned char)*name)
or if you like:
        isalnum((int)(unsigned char)*name)

Yes, I think that solaris' ctype implementation is a giant bug, but Sun 
usually has some good reason for not fixing it.

The use of <ctype.h> is likely to go away when implementing utf-8 support, so 
it is probably best just to live with the ugly "unsigned char" casts :-/

Regards,
  Ivan
--
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to