473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how can I find out all the unused functions?

hi, all.

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.

thanks.
Nov 14 '05 #1
2 3522
bugzilla wrote:
hi, all.

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:
This is completely compiler-dependent. Such questions usually belong in
compiler-specific newsgroups.

#include <stdio.h>
int Nouse();

int main()
{
printf("Hello,world!");
main returns an int; it is good practice to do so. }

int Nouse()
{
printf("I am used!");
You claim that Nouse returns an int; it should do so
}

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.


<ot>
Again, this is compiler-specific. I'll let you in on a secret, though,
if you don't tell anyone I answered an off-topic question. Most
versions of gcc won't warn you of unused functions unless they are
static. That is because a function which has external linkage may be
used in another part of the program not in this file. If you mark the
function as static, -Wunused-function or -Wunused might do the job.
</ot>
Nov 14 '05 #2
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.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sam Smith | last post by:
Hi, I'm thinking about whether or not to build a general library on its own and later link that lib with the main executable, or to build the main executable with a subset of the relevant source...
35
by: Geronimo W. Christ Esq | last post by:
Are there any scripts or tools out there that could look recursively through a group of C/C++ source files, and allow unreferenced function calls or values to be easily identified ? LXR is handy...
6
by: Dom Gilligan | last post by:
Does anyone know of a C++ lint, preferably free? I've inherited a large code base and need to remove some unused functions. What I've found so far: gcc -O2 does *not* check for unused functions...
6
by: Chris Stankevitz | last post by:
At link time, MSVC determines some of my libraries are unused and doesn't link them into my exe. This undesirable feature causes problems when I employ the factory pattern. With the factory...
9
by: ThazKool | last post by:
I am just wondering if all the methods that are never called upon during a programs execution are removed when optimizing. For example you have: class FooA { void a(); ... void z(); }
11
by: Charles Sullivan | last post by:
I have a number of functions, e.g.: int funct1( int arg1, int arg2, int arg3 ); int funct2( int arg1, int arg2, int arg3 ); int funct3( int arg1, int arg2, int arg3 ); that are called via...
8
by: Frank Rizzo | last post by:
Is there a setting in VS2005 to quickly locate methods that are unused (maybe through compiler warnings)? If not, any utilities out there that do that? Thanks
33
by: jacob navia | last post by:
Hi I am considering extending the lcc-win32 compiler to accept int fn(int a, int b,double) { // body of the function } This allows the programmer to specify that the third parameter is not...
10
by: Joris Dolderer | last post by:
Hello, I want to compile and link a program statically against the dietlibc. Of course, the dietlibc includes functions my program never needs. Is there any way to throw them out of the final...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.