Solved

Filtering out unused functions .

Posted on 2001-07-02
8
276 Views
Last Modified: 2008-02-01
Hi All
I was wondering if there is an easy way to know whether a function in a project is used or not.
The reason for this is , I have a project devoleped over the years by so many programmers and have a
lot of redundant functions in it which may be not used in the currect version.

I am using vc++ 6.0
I tried with profiler but it gives only information about the functions executed at runtime.

Any help is greatly appreciated
thanks
Fleming
0
Comment
Question by:softfgk
8 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6246025
The VC++ linker automatically leaves unused functions out of the linked EXE or DLL.  If you want to
see what is included, use the Visual Studio DEPENDS.EXE tool or the command line tool DUMPBIN /IMPORTS
0
 

Author Comment

by:softfgk
ID: 6246186
well that will show which all functions have you imported into ur exe module.
thats not what i want.
I am looking for someway to findout unused functions within that EXE
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6247084
Hi,
In ClassView select the function that you want to view->Right click->Select References...->Press Yes to Generate Browse Information->The Definition and References window of that function will appears->look at the references section for your information.
0
 
LVL 22

Expert Comment

by:ambience
ID: 6247210
This is not easy , linker is perhaps the best entity to do this kind of work.

>>> whether a function in a project is used or not.

That is not easy to determine , it may be possible to have a function that is not used in the project but that is emitted in the generated code.

A function that is referenced or whose address is taken is emitted ofcourse , so if there is a table of pointers to funcs somewhere in the code and even though only some of the entries are actualy being used , all the referenced functions are in the code.

This also depends on the settings you make while compiling , a linker has the option to either bring a whole COMDAT record into the code or exclude it , so if the compiler is not packaging individual functions per COMDAT there are possibly unused functions in the code.

Turn on optimization thru /Gy and /OPT:REF so that the linker discards any function not used.

Add a table of void *'s and take address of all the functions in the project (yikes) , print the table. This causes all the functions to remain in the code. Now keep on removing function entries from table by setting them to 0 and monitor code-size changes , this can help estimate if a function is there is the code or discarded.

Pretty messy procedure but i cant think of any other unless someone else has found a real bright tool or idea. somebody correct me if i am wrong ...
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6247292
usually, I use grep utility , that makes me all
references fo some string in directory:
grep MyFunc *.cpp -> all cpp files with MyFunc + places
in files.
0
 
LVL 5

Accepted Solution

by:
proskig earned 100 total points
ID: 6248050
I have been using Understand for C++ utility (you can download 14 days eval. version).

Among different reports it shows a report about unused identifiers.
0
 

Author Comment

by:softfgk
ID: 6249557
Hi guys
Understanding for c++ really did what i wanted
Initially i was going for rational pure coverage and numega true coverage. But both gives runtime analysis only

thanks all for ur suggestions
Fleming
0
 
LVL 11

Expert Comment

by:griessh
ID: 6820166
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "proskig" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now