GCC oddity
Kevin O'Gorman
kogorman
Mon May 17 11:47:15 PDT 2004
I have a short program that provokes an error when compiled on
some versions of gcc, and I cannot figure out why. I'm using
the stock gcc that came with RedHat 7.1 (gcc 2.96-81)
The program is simple:
##################### CUT HERE ###################################
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int
main(){
int r;
struct stat buf;
r = lstat(".", &buf);
return r;
}
##################### CUT HERE ###################################
And I use a simple makefile:
##################### CUT HERE ###################################
CC =gcc
CFLAGS = -g -Wall -ansi -pedantic
foo: foo.c
bar.c: foo.c
gcc -E $< | perl -p -e 's:(#.*):/* \1 */:' >$@
clean:
rm bar* foo.o foo
##################### CUT HERE ###################################
If I use the command 'make foo' I get
> gcc -g -Wall -ansi -pedantic foo.c -o foo
> foo.c: In function `main':
> foo.c:10: warning: implicit declaration of function `lstat'
But I don't get this warning if I use the preprocessor to
make a source file without includes. This should be identical
to the results for foo.c, but if I use the command 'make bar'
I get:
> gcc -E foo.c | perl -p -e 's:(#.*):/* \1 */:' >bar.c
> gcc -g -Wall -ansi -pedantic bar.c -o bar
I had expected the same error with the constructed bar.c, so that
I could narrow down the cause of the error, but this is quite
frustrating.
Any ideas?
++ kevin
More information about the Linux-users
mailing list