CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2008
    Posts
    38

    remove debug statements

    Is there a way to remove debug statements (usually protected by #defines) from the source code?

    I guess it would depend on the source code editor, but has anyone found a way to do this?

  2. #2
    Join Date
    Nov 2006
    Posts
    1,611

    Re: remove debug statements

    I don't think there are any tools or features in the editors that do this.

    The whole purpose of using defines and similar means (macros that mean nothing in release compilations, for example) is that they all evaporate in a release build.

    I know, it's clutter.

    Search/replace - or search and manually destroy - it's about all there is.
    If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).

  3. #3
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: remove debug statements

    Under UNIX/Cygwin there is sed, the stream editor. It allows you delete regions starting and ending with a regexp match. Assuming your code looks something like this:
    Code:
    #include <iostream>
    
    #ifdef _DEBUG
    #include <debugstuff.h>
    #endif
    
    int main() {
    #ifdef _DEBUG
      std::cout << "DEBUG\n";
    #endif
    
      std::cout << "Hello World" << std::endl;
    }
    The following sed command would "clean this up":
    Code:
    sed -e'/^#ifdef  *_DEBUG/,/^#endif/d' <filename>
    Then a bit of UNIX knowledge to run this on all files:
    Code:
    for FILE in `find . -type f -name '*.h' -o -name '*.cpp'`; do
    cp $FILE $FILE.bkp
    sed -e'/^#ifdef  *_DEBUG/,/^#endif/d' $FILE.bkp >$FILE
    done
    Warning though: This is simple line matching, so if you have a nested #ifdef/#endif within the debug code, this will fail.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  4. #4
    Join Date
    Aug 2007
    Posts
    858

    Re: remove debug statements

    Why do you want to remove this kind of stuff? It doesn't affect your program's speed. It should only have the tiniest affect on compilation times. It's generally there for a reason.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured