Miscellaneous interesting things

Scott Tringali scott.tringali at totalviewtech.com
Mon Oct 15 20:19:47 CEST 2007


Ivan Skytte Jørgensen wrote:

> I just checked values -128..255 on Solaris 8 with isdigit() and isalpha():
> Plain program:
> 	-128..-1: bogus;  0..127: ok;   128..255: all-0/ok
> Program with setlocale(LC_CTYPE,""):
> 	-128..-1: bogus;  0..127: ok;   128..255: all-0/ok (??)
> Program with setlocale(LC_CTYPE,"") and LC_CTYPE=en_US.UTF-8
> 	-128..-1: bogus;  0..127: ok;   128..255: all-0/ok
> Program with setlocale(LC_CTYPE,"") and LC_CTYPE=nl_BE.ISO8859-1
> 	-128..-1: bogus;  0..127: ok;   128..255: ok
> 
> So I can confirm that the is..() functions are quite weird on Solaris for 
> negative values. The default character type on Solaris is signed.
> 
> So I agree: the casts should stay. A comment somewhere in the sources on why 
> it is done would be a good idea. Allthough I wonder what can go wrong in 
> nedit if isdigit() etc. return random but consistent values.

A better way probably would be to avoid stroul here (because it forces 
use of a "plain char") and use sscanf directly into an int (because 
that's what isdigit takes).

If that doesn't work, another solution would be to wrap to isupper (etc) 
so that it can be called without the cast.  The wrapper would do the 
proper fixups and then the explanation would only need to be in one palce.


More information about the Develop mailing list