This is the mail archive of the
mailing list for the GCC project.
Should we make "implicit declaration of function" a mandatory warning?
- To: gcc at gcc dot gnu dot org
- Subject: Should we make "implicit declaration of function" a mandatory warning?
- From: "Zack Weinberg" <zackw at stanford dot edu>
- Date: Sun, 14 Jan 2001 23:49:23 -0800
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
printf("exp(1):%g exp2(1):%g exp10(1):%g\n",exp(1.0),exp2(1.0),exp10(1.0));
$ gcc test.c -lm
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.