2025-12-02 10:10 AM
I'm running into a strange issue: the following function compiles cleanly on one machine but triggers a compiler error on another. Both machines are running the same version of STM32CubeIDE (2.0.0), and the project is shared via a Git repo on Azure DevOps.
Here is the function in question:
#ifdef __cplusplus
extern "C" {
#endif
#include "aws_iot_json_utils.h"
#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <stm32l4xx.h>
IoT_Error_t parseUnsignedInteger8Value(uint8_t *i, const char *jsonString, jsmntok_t *token) {
if(token->type != JSMN_PRIMITIVE) {
IOT_WARN("Token was not an integer");
return JSON_PARSE_ERROR;
}
if(('-' == (char) (jsonString[token->start])) || (1 != sscanf(jsonString + token->start, "%" SCNu8, i))) {
IOT_WARN("Token was not an unsigned integer.");
return JSON_PARSE_ERROR;
}
return SUCCESS;
}And here is the compiler error:
../Controller/mqtt/aws_iot_json_utils.c:84:101: error: expected ')' before 'SCNu8'
84 | if(('-' == (char) (jsonString[token->start])) || (1 != sscanf(jsonString + token->start, "%" SCNu8, i))) {
| ~ ^~~~~~
|
What am I missing?
I'm trying to understand why one machine accepts the SCNu8 macro from <inttypes.h> while the other rejects it, even though both environments should be identical. Any ideas on what could cause this discrepancy? Thanks.
2025-12-02 10:31 AM
> What am I missing?
a comma after "%" .
hth
KnarfB
2025-12-02 10:36 AM
If that's the case, it would fail on both machines.
I actually can fix the compile error by adding the preprocessor macro _WANT_IO_C99_FORMATS to this particular file. However, on the other machine, I don't have to, and that's the puzzle.
2025-12-02 10:46 AM
I see. Maybe this one helps: Solved: SCNu8 formatting - STMicroelectronics Community
2025-12-02 11:41 AM
@achen2556 wrote:And here is the compiler error:
../Controller/mqtt/aws_iot_json_utils.c:84:101: error: expected ')' before 'SCNu8'
84 | if(('-' == (char) (jsonString[token->start])) || (1 != sscanf(jsonString + token->start, "%" SCNu8, i))) {
| ~ ^~~~~~
|
You need to use the 'Preformatted' style to show that message properly - with the little pointer pointing to where the error is:
../Controller/mqtt/aws_iot_json_utils.c:84:101: error: expected ')' before 'SCNu8'
84 | if(('-' == (char) (jsonString[token->start])) || (1 != sscanf(jsonString + token->start, "%" SCNu8, i))) {
| ~ ^~~~~~
|
See:
2025-12-02 1:10 PM
Thanks for the posting tip, Andy.
Instead of adding the preprocessor macro _WANT_IO_C99_FORMATS, would it be preferable to simply add these two #define statements directly in the C module?
#define SCNu8 "hhu" /* uint8_t */
#define SCNi8 "hhi" /* int8_t */
I’m migrating a project from a Microchip PIC32MX to an STM32 platform. The module aws_iot_json_utils.c/h compiles without issues using Microchip’s XC32 compiler, where the system header inttypes.h ultimately maps SCNu8 and SCNi8 to "hhu" and "hhi" respectively. On the STM32 toolchain, these macros are not defined unless _WANT_IO_C99_FORMATS is used, prompting the question of whether defining these two macros locally would be the cleaner approach.
2025-12-02 10:28 PM
_WANT_IO_C99_FORMATS is newlib specific, not standard C99. So, it makes sense adding the defines to your code, maybe wrapped in an #ifndef block testing if they already exist.
hth
KnarfB