Code Cleanup Tool

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Neuhaus

    Code Cleanup Tool

    Hi
    sorry - I guess this is slightly OT but still ;)

    Iam looking for some tool (win32 please) that can find unused member
    functions / member variables in my project. Does anyone have any suggestions
    there? Google didnt help me much :/

    Thanks in advance


  • Gernot Frisch

    #2
    Re: Code Cleanup Tool


    "Frank Neuhaus" <fneuhaus@uni-koblenz.deschri eb im Newsbeitrag
    news:ean34c$v4b $1@cache.uni-koblenz.de...
    Hi
    sorry - I guess this is slightly OT but still ;)
    >
    Iam looking for some tool (win32 please) that can find unused member
    functions / member variables in my project. Does anyone have any
    suggestions there? Google didnt help me much :/
    Visual Studio >=7.0 with warning level set to "scream-at-me(tm)(c)(R)"


    Comment

    • Frank Neuhaus

      #3
      Re: Code Cleanup Tool

      Visual Studio >=7.0 with warning level set to "scream-at-me(tm)(c)(R)"

      Thanks for your reply. I just tried that. It already helped a bit - it
      reports unreachable code inside functions, unused parameters and unused
      global functions. But unfortunately it doesnt report unused member
      functions/variables :(


      Comment

      • Gernot Frisch

        #4
        Re: Code Cleanup Tool

        >Visual Studio >=7.0 with warning level set to
        >"scream-at-me(tm)(c)(R)"
        >
        Thanks for your reply. I just tried that. It already helped a bit -
        it reports unreachable code inside functions, unused parameters and
        unused global functions. But unfortunately it doesnt report unused
        member functions/variables :(
        unused variables should be listed:

        void foo()
        {
        int a;
        int b=0;
        }

        warning C4101: 'a' : unreferenced local variable
        warning C4189: 'b' : local variable is initialized but not referenced

        for unused functions - the linker will usually get rid of them. No, I
        don't know any tool that can list this for you, because only the
        linker knows what functions are used.


        Comment

        • David

          #5
          Re: Code Cleanup Tool

          Hello Frank,

          On Tue, 1 Aug 2006 09:30:08 UTC, "Frank Neuhaus" <fneuhaus@uni-koblenz.dewrote :
          Visual Studio >=7.0 with warning level set to "scream-at-me(tm)(c)(R)"
          >
          Thanks for your reply. I just tried that. It already helped a bit - it
          reports unreachable code inside functions, unused parameters and unused
          global functions. But unfortunately it doesnt report unused member
          functions/variables :(
          You might also try one of the "lint for C++" or static analysis tools
          (Klockwork 7?). In general, unused variables and methods in classes
          would be very hard to suggest that they weren't used. The linker
          could perform such a step if there wasn't a chance that the code/vars
          wouldn't be found by other means. Classes do much more than just
          group together values and functions that may be unused.

          Classes are abstractions of objects that your application may use.
          The fact that you don't make use of a particular method doesn't
          necessarily mean that it should be removed. You might be planning
          on using that component later. The class is a building block for
          others to build on. Hopefully the abstraction was valid.

          Static analysis tools can find such items to remove. These tools
          aren't cheap though. I've not read why you want to remove the
          unused components from your code.

          I generally review my legacy classes as I work with them to
          understand if the abstractions are valid. There are times that
          they get rewritten. Certainly if you think a method or value
          isn't used -- comment it out, compile, link, and look for the
          errors. With less common value/method names you might be able
          to get away with a search on the source code.

          David

          Comment

          • Frank Neuhaus

            #6
            Re: Code Cleanup Tool

            unused variables should be listed:
            >
            void foo()
            {
            int a;
            int b=0;
            }
            >
            warning C4101: 'a' : unreferenced local variable
            warning C4189: 'b' : local variable is initialized but not referenced
            >
            for unused functions - the linker will usually get rid of them. No, I
            don't know any tool that can list this for you, because only the linker
            knows what functions are used.
            I meant member variables - anyway... I know its not relevant for the actual
            compiler, but Id like to clean up my code and its kinda hard to do it
            manually as the code is too big to instantly know which function is used,
            which one is deprecated etc...

            So if anyone else has suggestions -...


            Comment

            • Christian Gollwitzer

              #7
              Re: Code Cleanup Tool

              Frank Neuhaus wrote:
              Iam looking for some tool (win32 please) that can find unused member
              functions / member variables in my project. Does anyone have any suggestions
              there? Google didnt help me much :/
              You could try running doxygen over the whole project. If you enable the
              "source code browser", it writes a "referenced by..." entry to all
              function/member descriptions. You could maybe even tweak it (its
              opensource) to output every unreferenced function/member to stderr.

              However, beware that virtual member functions are not referenced in this
              sense, since this is a static analysis.

              Christian

              Comment

              Working...