Search code examples
cc99printfc89

Implicit declaration of snprintf


I noticed that when I compile this iniparser it spits the following warning:

 src/iniparser.c:244:5: warning: implicit declaration of function ‘snprintf’ [-Wimplicit-function-declaration]
     snprintf(keym, secsize, "%s:", s);

The solution was supposedly to add:

#include <stdio.h>

I tried this, but that alone didn't solve the problem. Then I looked into the compile flags inside the Makefile, and found this:

 CFLAGS  += -fPIC -Wall -ansi -pedantic

If I changed this to:

 CFLAGS  += -fPIC -Wall -std=c99 -pedantic

It compiled with out a warning. Does this mean that the C90 standard does not include snprintf ? Can someone explain this behaviour to me?


Solution

  • snprintf is specified only in C99, unlike sprintf which is in C90. See man sprintf for more information.