cancel
Showing results for 
Search instead for 
Did you mean: 

Build failed on one Windows 11 machine but succeeded on the other.

achen2556
Associate II

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.

 

6 REPLIES 6
KnarfB
Super User

What am I missing?

a comma after  "%" .

hth

KnarfB

 

achen2556
Associate II

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.

Andrew Neil
Super User

@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: 

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/725146/highlight/true#M54

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
achen2556
Associate II

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.

_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