2023-11-04 02:49 PM
Hi,
I was expecting to get x = 23 after following code:
uint8_t x ;
char* y = "23" ;
sscanf ( y , SCNu8 , &x ) ;
but I got x = 32.
Solved! Go to Solution.
2023-11-04 03:06 PM
From comment in inttypes.h:
NOTICE: scanning 8-bit types requires use of the hh specifier
* which is only supported on newlib platforms that
* are built with C99 I/O format support enabled. If the flag in
* newlib.h hasn't been set during configuration to indicate this, the 8-bit
* scanning format macros are disabled here as they result in undefined
* behaviour which can include memory overwrite.
Build config of newlib is in ... tools/arm-none-eabi/include/newlib-nano/newlib.h and there _WANT_IO_C99_FORMATS is not enabled. Hope this answers your question, see also here.
2023-11-04 03:05 PM
What does sscanf() return?
What is SCNu8 ?
uint8_t x = 0;
char* y = "23" ;
int z = sscanf ( y , SCNu8 , &x ) ;
2023-11-04 03:06 PM
From comment in inttypes.h:
NOTICE: scanning 8-bit types requires use of the hh specifier
* which is only supported on newlib platforms that
* are built with C99 I/O format support enabled. If the flag in
* newlib.h hasn't been set during configuration to indicate this, the 8-bit
* scanning format macros are disabled here as they result in undefined
* behaviour which can include memory overwrite.
Build config of newlib is in ... tools/arm-none-eabi/include/newlib-nano/newlib.h and there _WANT_IO_C99_FORMATS is not enabled. Hope this answers your question, see also here.
2023-11-04 03:24 PM - edited 2023-11-04 03:25 PM
Would suggest inter-staging via an unsigned int.
uint8_t sscanf_u8(char *string)
{
unsigned int x = 0;
return(sscanf(string, "%u", &x) == 1 ? (uint8_t)x : 0 );
}