C++ lint (detection of unused classes and functions)?

D

Dom Gilligan

Does anyone know of a C++ lint, preferably free? I've inherited a
large code base and need to remove some unused functions. What I've
found so far:

gcc -O2 does *not* check for unused functions

gcc -Wanything-you-can-think-of doesn't check for unused non-static
functions

lclint/splint doesn't do C++

Gimpel FlexeLint/PC-lint (http://www.gimpel.com/html/lintinfo.htm)
should do the job, but it's $1000 and I'm broke

clint (http://sourceforge.net/projects/clint/) appears to be dead

lwlint (http://www.jimbrooks.org/web/tools/) might do the job, but I'd
have to build it from source to find out

Cheers

Dom
 
G

Greg

Dom said:
Does anyone know of a C++ lint, preferably free? I've inherited a
large code base and need to remove some unused functions. What I've
found so far:

gcc -O2 does *not* check for unused functions

gcc -Wanything-you-can-think-of doesn't check for unused non-static
functions

lclint/splint doesn't do C++

Gimpel FlexeLint/PC-lint (http://www.gimpel.com/html/lintinfo.htm)
should do the job, but it's $1000 and I'm broke

clint (http://sourceforge.net/projects/clint/) appears to be dead

lwlint (http://www.jimbrooks.org/web/tools/) might do the job, but I'd
have to build it from source to find out

Cheers

Dom

A compiler is not going to be able to identify uncalled routines, so
gcc is probably not the best place to look. After all, a compiler
compiles only one file at a time. How is it going to know that a
function in one file will not be called by some other function in a
different, not yet compiled file?

A compiler doesn't have that information, but a linker does. What you
are looking for is a linker that performs dead code stripping. Most
commercial linkers will remove unreferenced code and data. Apple
modified "ld" to do this, so perhaps their work has been incorporated
into the ld linker on your platform.

Greg
 
D

Dom Gilligan

A compiler is not going to be able to identify uncalled routines, so
gcc is probably not the best place to look. After all, a compiler
compiles only one file at a time. How is it going to know that a
function in one file will not be called by some other function in a
different, not yet compiled file?

True. The only reason I mentioned gcc is that the -O2 'solution'
appeared several times when googling c.l.c++, so I thought I'd point
out that it doesn't work (I did actually try it, though, it case it
does something clever when invoking the linker). There has also been
discussion of using the linker to do this, but it was inconclusive, so
I was hoping to get some mmore recent feedback...
A compiler doesn't have that information, but a linker does. What you
are looking for is a linker that performs dead code stripping. Most
commercial linkers will remove unreferenced code and data. Apple
modified "ld" to do this, so perhaps their work has been incorporated
into the ld linker on your platform.

Greg

Cheers

Dom
 
D

David

Does anyone know of a C++ lint, preferably free? I've inherited a
large code base and need to remove some unused functions. What I've
found so far:

Okay, you have a new-to-you large code base. Why would your nearly
first reaction be to look for tools to remove unused functions? Why
would you presume that they could not be of importance and that they
should be discarded?

As has been pointed out by another response, the linker is your
first tool that could determine what code is not used and what can be
omitted from the final product.

Another source for your information could be the reports that the
linker can be asked to generate for you.

Even if you are able to quickly discover the code that "does not
immediately appear useful", why do you wish to discard it? Why
did the original writers create that code in the first place?

If your answer is something along the lines of "the code supports
multiple (OSes, build environments, etc) and I don't need that
now" is the code actually worth removing? You may find that you
will need it later and getting it back may not be very easy once
you've started modifying the result.

So you might want to be clear why you are pursuing this course
of action before you choose to act on it. You need not answer
us. I just hope you don't find the code you delete today is
the code you end up redeveloping next week.

David
 
D

Dom Gilligan

Okay, you have a new-to-you large code base. Why would your nearly
first reaction be to look for tools to remove unused functions? Why
would you presume that they could not be of importance and that they
should be discarded?

As has been pointed out by another response, the linker is your
first tool that could determine what code is not used and what can be
omitted from the final product.

Another source for your information could be the reports that the
linker can be asked to generate for you.

Even if you are able to quickly discover the code that "does not
immediately appear useful", why do you wish to discard it? Why
did the original writers create that code in the first place?

So you might want to be clear why you are pursuing this course
of action before you choose to act on it. You need not answer
us. I just hope you don't find the code you delete today is
the code you end up redeveloping next week.

David

I've been rewriting this code for the past six months. I want to
remove these unused functions because they're now, well, unused, like
the subject says.

Previous discussion on this list has indicated that it could be
problematical to use a linker to do this, even for the very limited
number of linkers that might have this functionality. That's why I
said:
There has also been
discussion of using the linker to do this, but it was inconclusive, so
I was hoping to get some mmore recent feedback...

in my reply to Greg.

Dom
 
C

Chris Hills

Dom Gilligan said:
Does anyone know of a C++ lint, preferably free? I've inherited a
large code base and need to remove some unused functions. What I've
found so far:

Gimpel FlexeLint/PC-lint (http://www.gimpel.com/html/lintinfo.htm)
should do the job, but it's $1000 and I'm broke


Use PC-Lint. That is about 239 USD.

It does C++

It will spot unused functions.
All you have to do is drop the source on to a Windows platform.
 
D

Dom Gilligan

Use PC-Lint. That is about 239 USD.

It does C++

It will spot unused functions.
All you have to do is drop the source on to a Windows platform.

Interesting - I hadn't thought of that. Makes you wonder why they do
the Unix version at $1000. And they don't even offer a demo.

Cheers

Dom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top