mo**************@gmail.com (bugzilla) writes:
I want to know which flag can be used to give me a warning that one
declared function is not called in the program. for example:
#include <stdio.h>
int Nouse();
int main()
{
printf("Hello,world!");
}
int Nouse()
{
printf("I am used!");
}
I want gcc can tell me that althoug int Nouse() was declared and
implemented, but it is not called in the program. I tried to use
-Wall, but it doesnot work.
There's no reason to issue a warning for the above code (at least not
for the lack of a call to Nouse(). Nouse isn't called from within
that file, but it could be called from another separately compiled
source file.
If Nouse were declared static, a warning would be appropriate, since
the function would be visible only from that source file. gcc comes
with extensive documentation, which should tell you how to get it to
generate such a warning if it doesn't do so by default. (One hint:
you can sometimes get more warnings at higher optimization levels; the
analysis the compiler has to do to perform optimizations can reveal
problems that aren't detected at lower levels.)
(You probably can expect warnings for the failure to return values
from functions declared to return int. It's also better to declare
"int Nouse(void)" rather than "int Nouse()"; likewise for main.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.