implicit declaration warning only when using std=c99

Ian Lance Taylor
Thu Aug 17 17:03:00 GMT 2006

Glen Beane <> writes:

> I have been developing a C program using gcc 4 on Apple OS X.  Today I copied my source over to a quad core AMD Opteron box running SuSE linux with gcc v 3.3.3 and compiled.
> I have been compiling this program with -std=c99 so that I can declare variables inside of a for loop statement
> e.g. for (int i = 0; i <foo; i++)
> on the suse box,  I would get implicit declaration warnings for strdup, strtok_r, and lstat.  I verified that I was including the proper .h files, and no such warnings were produced on the OS X box.
> I made the following test program and determined that I only got the warning if I used -std=c99.  -std=gnu99 did not produce warnings,  nor did the default std.  I then tried compiling the test program with -std=c99 -D_GNU_SOURCE and it did not produce the warnings.   What is it about -std=c99 on this system that requires _GNU_SOURCE to be defined in order for the prototypes for strdup, strtok_r, and lstat to be properly included?   Should I just compile my program with -std=gnu99 and forget about it?

--std=c99 requests the exact ISO C99 environment specified by the
standard.  strdup, strtok_r, and lstat are not defined by ISO C99.
Therefore, the header files do not declare them in that environment.

--std=gnu99 requests ISO C99 plus the GNU extensions, which includes
all the usual Unix functions.  Therefore, in that environment, those
functions are declared by the header files.

The way this works is that --std=c99 causes the feature test macro
__STRICT_ANSI__ to be defined.  That macro affects what the header
files declare.

-D_GNU_SOURCE overrides __STRICT_ANSI__ and directs the header files to
declare the usual Unix functions.

There is more information on_GNU_SOURCE and friends here:
Where that page refers to -ansi, it also means -std=c90 and -std=c99.


More information about the Gcc-help mailing list