Andrey Chernov <a...@nagual.pp.ru> writes:
> "Simon L. Nielsen" <si...@freebsd.org> writes:
> > Acording to the manual page and the C standard book I have,
> > isdigit() takes an int for an argument, so why change this?
> "The value of the argument must be representable as an unsigned char or
> the value of EOF."
>
> Signed char (automatically casted to int in expression even without direct 
> (int) cast) passed to any ctype macro potentically may cause a lot of 
> problems, such as: incorrect char class detection or even core dump in 
> some systems.
>
> This is due to automatic sign extension of 8bit (if present).

To put it more clearly:

 - The is*() functions expect an int for the same reason fgetc() returns
   one: a char alone can't represent all possible char values *plus*
   EOF.

 - In most 8-bit locales, there are valid characters outside the 0-127
   range.  When stored in a signed char, such characters are represented
   as negative values.  When that signed char is promoted to a signed
   int, the negative values remain negative instead of being converted
   to the correct positive value.

 - This would not be a problem if C distinguished between a character
   (unsigned) and a "short short int" (signed).

 - The core dump ache refers to can occur with a naïve implementation
   that uses a lookup table and checks for EOF, but not for other
   negative values.

DES
-- 
Dag-Erling Smørgrav - d...@des.no
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to