Also consider printf("%hhu", c); to precisely specify the conversion to unsigned char and print its decimal value.
Update0
So, I really tested this on my C compiler to find out what happens, the results are interesting:
char c = '\xff'; printf("%c\n", c); printf("%u\n", c); printf("%d\n", c); printf("%hhu\n", c);
This is what is printed:
(printed as ASCII) 4294967295 (sign extended to unsigned int) -1 (sign extended to int) 255 (handled correctly)
Thanks to caf that types can advance in unexpected ways (which seems to be the case for %d and %u ). Also, it seems that the %hhu case is returning to char unsigned , possibly by disabling character embroidery.
Matt joiner
source share