On 17-Apr-08, at 8:11 AM, Christos Zoulas wrote:
It is not an issue of avoiding the warnings. For example isspace() is
defined in:
http://www.opengroup.org/onlinepubs/009695399/functions/
isspace.html
as:
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 by casting a signed char to an int, you can get a large negative
number
and you end up with "undefined behavior" which might mean a core
dump,
so don't do it!
Argh! Sorry, I should have been able to figure that out myself,
given the usual implementations. My brain doesn't seem so good at
seeing the possibility of negative array indexing -- too many years
of sloppy assumptions.
However what you and Alan said about simply casting to (unsigned
char) isn't sufficient, at least on some platforms (IRIX-6, IIRC),
at least not to keep the compiler happy.
Sadly I do get the least warnings from every platform when the cast
is only to (int). I wonder if the compiler can be taught to detect
uses where a parameter may have a value out of range even though the
data type it is declared as is wide enough. The only solution the
compiler can really believe though, I think, would be a double cast
where the value is narrowed sufficiently before being widened again
for the call.