I am in 3-day fight with proper behavior of std functions such as vsscanf, sscanf.
My simplest code example:
int main() {
uint8_t baudrate = 0;
uint8_t databits = 0;
uint8_t stop_bits = 0;const char xformat[] = "%hhu %hhu %hhu\n"; const char xtext[] = "200 8 1\n"; int res = sscanf(xtext, xformat, &baudrate, &databits, &stop_bits); printf("Res: %d\r\n", res); printf("baudrate: %hhu, databits: %hhu, stop: %hhu, \r\n", baudrate, databits, stop_bits); while(1) { }
}
In this setting, the output is:
Res: 3
baudrate: 0, databits: 0, stop: 1,
I have tried different datatypes, patterns and modifiers (%hhu for uint8_t, %lu for uint32_t etc.),
every setting has its flaws (e.g. some of the variables zero)
Even if the Res variable returns 3 every time.
What proved to be working is making the variables static, or to make all variable uint32_t or ints,
but these are not acceptable solutions.
I am asking, why the standard libraries are not working as they supposed to be ?
I have cross-checked the behavior with mbed online compiler, where it works as expected.
Using RTOS or no-RTOS mbed makes no difference in PlatformIO.
- Visual Studio Code 1.43.2
- PIO Core 4.3.1
- PIO Home 3.1.1
- ST-STM 6.0.0