In the specific case of unsigned char foo
, there isn't a difference. If you tried:
#include <stdio.h>
int main(void)
{
signed char bar = '\xFF';
unsigned char foo = '\xFF';
printf("%hhx %x\n", bar, bar);
printf("%hhx %x\n", foo, foo);
return 0;
}
You'd typically get the output:
ff ffffffff
ff ff
The reason is that in both cases, the character is converted to an int
when it is passed to printf()
, but the signed character is converted to a negative int
, which is then processed by conversion to unsigned char
when the length modifier is hh
and is left at full size (4 bytes, I'm assuming) when the length modifier is omitted.