Re: how can I find out all the unused functions?

From: Keith Thompson (kst-u_at_mib.org)
Date: 03/22/05


Date: Tue, 22 Mar 2005 08:07:02 GMT

mozilla.bugzilla@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) kst-u@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.


Relevant Pages

  • Re: Program without conditional Statements - Possible ?
    ... >> a warning that, based on the cited text above, I think is ... > return an int, return an int; main is no different this respect than ... > most functions, if you don't want to return a value, you can declare ... it's easier just to be consistent about returning a value than ...
    (comp.lang.c)
  • Re: data type
    ... integer if we can't explicitly declare it at beginning of a program???? ... foo.c:3: warning: function declaration isn't a prototype ... foo.c:3: warning: type of `x' defaults to `int' ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Re: data type
    ... integer if we can't explicitly declare it at beginning of a program???? ... foo.c:3: warning: function declaration isn't a prototype ... foo.c:3: warning: type of `x' defaults to `int' ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Re: data type
    ... integer if we can't explicitly declare it at beginning of a program???? ... foo.c:3: warning: function declaration isn't a prototype ... foo.c:3: warning: type of `x' defaults to `int' ... Hmm, actually he got 3 warnings, your compiler produced 2 ...
    (comp.lang.c)
  • xemacs installation problems
    ... checking for gcc... ... checking whether we are using GNU C... ... checking size of int... ... configure: warning: No OffiX without generic Drag'n'Drop support ...
    (comp.os.linux.misc)