David Tiktin said:
In it's typical use:
char * ptr = str;
while (*ptr)
{
*ptr = TO_LOWER(*ptr);
ptr++;
}
There is no semantic difference.
some compilers I've used over the years complain about the
assignment of an int to a char due to loss of precision.
Assignment of int values to a char is probably the most
fundamental of useful constructs that C has. Putting a
warning on that is to me like putting a warning on every
#include asking if that's the file you actually meant to
include.
I generally run with the highest warning levels I can get,
A good move, but you shouldn't change code to silence one
compiler's warnings unecessarily. Different compilers will
issue warnings for different reasons and two different
compilers can even issue warnings for opposing reasons.
so the cast silences a warning I've investigated and found
not to be a problem in this situation.
The simpler option is to acknowledge that no action is
required as a consequence of the warning.
It's easy to fall into the belief that the absense of
warnings is a strong measure of correctness. 'Clean'
compiles give a sense of confidence. But it's a small
step away from introducing bugs, just to silence a
compiler.
Sorry, I don't understand your point here or where that
assumption is made.
Depending on how you use them, input routines often read
and store bytes, not (plain) chars. On an sm machine
interpreting an input byte as a char representation and
converting it to an unsigned char can potentially yield
a different character code to the original for some
characters outside the basic character set.
It's a highly unlikely scenario, and it's dismissed with
a little handwaving about QoI guaranteeing that 1c and sm
machines will always make plain char unsigned.
Is there a problem that the code should be:
*ptr = tolower((int)(*ptr) & 0xFF);
to assure the passed value and result are in the range
0-255 even if CHAR_BITS is greater than 8?
No. I'm suggesting, in some cases, it should be...
*ptr = tolower(* (unsigned char *) ptr);
Obviously that's not as aesthetic as the direct conversion
(unsigned char) *ptr, but it does have the advantage of
working on the hypothetical machines (contrived if you
like) as well as the vanilla ones.