The C language doesn't provide any way of specifying a literal with type char
or unsigned char
. Use the cast.
By the way, the result of your calculation is outside the range of unsigned char
, so the warning is quite correct - conversion will alter its value. C doesn't provide arithmetic in any type smaller than an int
. In this case I suppose that what you want is modulo-256 arithmetic, and I think that gcc will recognise that, and will not emit the warning with the casts in place. But as far as the C language is concerned, that calculation is done in the larger type and then converted down to unsigned char
for storage in ascii
.