Solved

Filtering out unused functions .

Posted on 2001-07-02
8
281 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixing C++ & C# in Vis Studio 2013 7 172
Compile GLUT with Visual Studio 2015 1 145
How can i compile this github project?? 2 84
What is sub-make ? 2 60
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.

770 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