implicit declaration warning only when using std=c99
Glen Beane
glen.beane@jax.org
Thu Aug 17 14:04:00 GMT 2006
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?
test program:
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
char *str = strdup(argv[0]);
printf("%s\n", str);
return 0;
}
--
Glen L. Beane
Software Engineer II
The Jackson Laboratory
Phone (207) 288-6153
More information about the Gcc-help
mailing list