Solved

Filtering out unused functions .

Posted on 2001-07-02
8
277 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

919 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