Solved

Filtering out unused functions .

Posted on 2001-07-02
8
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

636 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