For example such code may be useful:
unsigned char ch = 0xf2;
printf("%02hhx", ch);
However, ch
is promoted to int
when passing as a parameter of variadic function printf
. So when %hhx
is used, there is type mismatch. Is any undefined behavior involved here according to C standard? What if it is C++?
There are some discussion here but no answer is given.