Page 1 of 1

Printf and sscanf doesn't work for %hhx

Posted: Thu Apr 20, 2017 3:29 pm
by kostyan5
It appears that printf and sscanf don't work with %hhx (for unt8_t). %hx works just fine for uint16. I know that newlib nano doesn't support 64-bit. Does it not support 8-bit either?

Re: Printf and sscanf doesn't work for %hhx

Posted: Thu Apr 20, 2017 11:06 pm
by ESP_igrr
If you have selected nano formats option in newlib, hhx will not work (as all other C99 formats).

Re: Printf and sscanf doesn't work for %hhx

Posted: Thu Apr 20, 2017 11:14 pm
by kostyan5
So what's the proper way to sscanf a 2 or printf a uint8_t?

Re: Printf and sscanf doesn't work for %hhx

Posted: Thu Apr 20, 2017 11:59 pm
by ESP_igrr
You have two options:
- disable nano formatting and use these C99 formats
- like everyone did pre-C99, cast to an (unsigned) int in printf, and sscanf into an intermediate (unsigned) int variable, then copy into uint8_t.