Printf and sscanf doesn't work for %hhx

kostyan5
Posts: 50
Joined: Mon Mar 06, 2017 3:16 pm

Printf and sscanf doesn't work for %hhx

Postby kostyan5 » Thu Apr 20, 2017 3:29 pm

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?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Thu Apr 20, 2017 11:06 pm

If you have selected nano formats option in newlib, hhx will not work (as all other C99 formats).

kostyan5
Posts: 50
Joined: Mon Mar 06, 2017 3:16 pm

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

Postby kostyan5 » Thu Apr 20, 2017 11:14 pm

So what's the proper way to sscanf a 2 or printf a uint8_t?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Thu Apr 20, 2017 11:59 pm

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.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 183 guests