In function vTaskList,error: implicit declaration of function 'sprintf' occured

Hello,when I define configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS both as 1 for this function to be available in FreeRTOSConfig.h,and then make run ,it will occur some errors and warnings as follow:
core/FreeRTOS/Source/tasks.c:4305:5: error: implicit declaration of function ‘sprintf’ [-Werror=implicit-function-declaration]
core/FreeRTOS/Source/tasks.c:4305:5: warning: incompatible implicit declaration of built-in function ‘sprintf’.
Is there anyone who can help me? Thank you very much.

Although you provide not much context information (FreeRTOS version, compiler ?) it‘s not a big problem because sprintf is a standard C library function declared in <stdio.h> of your compiler toolchain. I think it should be automatically #include‘d by FreeRTOS (tasks.c) if configured accordingly e.g. with configGENERATE_RUN_TIME_STATS
However, you could verify if sprintf is properly declared in stdio.h of your compiler and if/where stdio.h is included by FreeRTOS sources or headers as it should.
Or just remove the -Werror flag :wink:

1 Like

I didn’t modify the task. C file, and checked that it contains the stdio header file,and then I verify sprintf is properly declared in stdio.h of my compiler.But it didn’t work .
Thank you so much for your reply. and I’m sorry to see it now. :blush:

Not having the FreeRTOS sources at hand … the warning is strange if stdio.h is included.
That shouldn’t happen…
For a quick and dirty check regarding #include and/or #define I’m sometimes patching e.g. stdio.h at the location of interest with a #warning “sprintf declared”right above the sprintf declaration and re-compile the source to be really sure things are as expected.
And revert the patch afterwards, of course.
Alternatively it’s possible to investigate the pre-processed source output adjusting the compiler flags accordingly. But this is a bit more effort.