This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDK Request: Make printf calls portable

When I add CFLAGS += -DENABLE_DEBUG_LOG_SUPPORT to an otherwise unchanged Nordic demo based on gcc, I get these errors everywhere:

../../../../../../components/ble/device_manager/device_manager_peripheral.c: In function 'application_instance_init': ../../../../../../components/ble/device_manager/device_manager_peripheral.c:582:5: error: format '%X' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t' [-Werror=format=] DM_TRC("[DM]: Initializing Application Instance 0x%08X.\r\n", index); ^

I'm using the RF52 SDK 0.9.2 in this case. I'm not sure if it's the same for other SDKs.

After reading this [1] link, it seems you could write the trace/printf calls such that you won't have this problem.

[1] stackoverflow.com/.../unsigned-int-is-not-uint32-t-when-compile-to-cortex-m0-possible-c-compiler-fl

The key code segment in that link is this:

The correct format for uint32_t is defined as a macro in <inttypes.h>:

uint32_t x = 42;
printf("x = %" PRIu32 "\n", x);

(PRIu32 expands to a string literal; this takes advantage of the fact that adjacent string literals are concatenated.)

EDIT: I can work around this by removing from CFLAGS '-Wall', though I wouldn't want to leave it that way permanently.

Related