This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Should we make "implicit declaration of function" a mandatory warning?


Someone filed a bug against glibc in Debian
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=71603) saying that
the exp2 and exp10 functions were broken.  He provided a test program:

$ cat test.c
#include <math.h>
#include <stdio.h>
int main(){
printf("exp(1):%g exp2(1):%g exp10(1):%g\n",exp(1.0),exp2(1.0),exp10(1.0));
return 0;
}
$ gcc test.c -lm
$ ./a.out
exp(1):2.71828 exp2(1):6.79039e-313 exp10(1):2.85969

This turns out to be user error: glibc doesn't prototype exp2 or exp10
without -D_GNU_SOURCE, so gcc thinks they return int, so it looks for
their return values in %eax instead of %st(0) [or the analogous
integer and float registers - this is quite cross-platform].

However, we could've done a lot better by the user.  With -Wall:

$ gcc test.c -lm -Wall
test.c: In function `main':
test.c:4: warning: implicit declaration of function `exp2'
test.c:4: warning: implicit declaration of function `exp10'
test.c:4: warning: double format, different type arg (arg 3)
test.c:4: warning: double format, different type arg (arg 4)

which makes quite clear that something's wrong.  What do people think
of promoting the "implicit declaration of function" warning to
mandatory?  These days it is far more likely to be a bug than
unregenerate K+R code...

Note that implicit declarations were removed from C99.

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]