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

Discussion in 'C++' started by Dom Gilligan, Aug 12, 2005.

  1. Dom Gilligan

    Dom Gilligan Guest

    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
    Dom Gilligan, Aug 12, 2005
    #1
    1. Advertising

  2. Dom Gilligan

    Greg Guest

    Dom Gilligan wrote:
    > 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
    Greg, Aug 12, 2005
    #2
    1. Advertising

  3. Dom Gilligan

    Dom Gilligan Guest

    On 12 Aug 2005 05:00:44 -0700, "Greg" <> wrote:

    >
    >Dom Gilligan wrote:
    >> 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?


    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
    Dom Gilligan, Aug 12, 2005
    #3
  4. Dom Gilligan

    David Guest

    On Fri, 12 Aug 2005 11:32:21 UTC, Dom Gilligan <> wrote:

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

    <snip>
    >
    > Dom


    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
    David, Aug 14, 2005
    #4
  5. Dom Gilligan

    Dom Gilligan Guest

    On Sun, 14 Aug 2005 12:30:56 GMT, "David" <>
    wrote:

    > 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
    Dom Gilligan, Aug 16, 2005
    #5
  6. Dom Gilligan

    Chris Hills Guest

    In article <>, Dom Gilligan
    <> writes
    >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.


    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    Chris Hills, Aug 16, 2005
    #6
  7. Dom Gilligan

    Dom Gilligan Guest

    On Tue, 16 Aug 2005 19:12:12 +0100, Chris Hills <>
    wrote:

    >In article <>, Dom Gilligan
    ><> writes
    >>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.


    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
    Dom Gilligan, Aug 18, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    5
    Views:
    2,194
  2. Geronimo W. Christ Esq

    Removing dead code and unused functions

    Geronimo W. Christ Esq, Jun 19, 2005, in forum: C Programming
    Replies:
    39
    Views:
    2,243
    Dave Thompson
    Jul 4, 2005
  3. Dan Henry
    Replies:
    0
    Views:
    382
    Dan Henry
    Jun 21, 2005
  4. Greg
    Replies:
    10
    Views:
    1,511
    Dave Thompson
    Jul 4, 2005
  5. David Sudolcan
    Replies:
    7
    Views:
    2,025
    Eric Sosman
    Apr 4, 2011
Loading...

Share This Page