Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit declaration of snprintf

Tags:

c

printf

c99

c89

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?

like image 750
oz123 Avatar asked Mar 25 '14 22:03

oz123


1 Answers

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

like image 123
nneonneo Avatar answered Oct 11 '22 16:10

nneonneo