Solved

Filtering out unused functions .

Posted on 2001-07-02
8
286 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
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!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which IDE to use to begin C++ training? 5 76
ASP.net build a IF/Then Walkthrough Guide 1 317
Unable to start eclipse ? 17 173
Problem with SqlConnection 4 193
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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