|
-
July 10th, 2009, 09:10 AM
#1
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?
-
July 10th, 2009, 02:59 PM
#2
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).
-
July 10th, 2009, 03:13 PM
#3
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.
-
July 10th, 2009, 03:25 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|