2023-08-08 05:52 AM
Hi,
I have some code with a call to sscanf from libc.a.
The code is as follow:
uint8_t arg1;
char arg2[7];
char arg3[64];
uint16_t arg4;
uint16_t arg5;
char arg6[8];
sscanf( msg,
"%hhu,\"%[^\"]\",\"%[^\"]\",%hu,%hu,%hhu",
&arg1,
arg2,
arg3,
&arg4,
&arg5,
&arg6);
msg is for instance:
+CIPSTATE:0,"TCP","52.215.18.77",80,55033,0\r\n
I have built it with both STM32CubeIDE embedded libraries, and standard ARM libraries, version 10.3.1.
This code works with STM32CubeIDE libraries, but not with standard ARM toolchains.
Interestingly enough, if I use %d instead of %hhu and let it silently cast, it seems like it works with the default toolchain too.
"%d,\"%[^\"]\",\"%[^\"]\",%hu,%hu,%d"
Is there an explaination for this behaviour?
Are ther implementation differences between libc.a sscanf from the standard ARM toolchain distribution and from the STM32CubeIDE distributed toolchain?
2023-08-08 06:30 AM
Looks like %hhu is not a standard specifier and implementations treat it differently. Might want to stick with the standards if you want your code to be portable. %u, %d is certainly going to work the same on all implementations.