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?
Printable View
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?
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.
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:The following sed command would "clean this up":Code:#include <iostream>
#ifdef _DEBUG
#include <debugstuff.h>
#endif
int main() {
#ifdef _DEBUG
std::cout << "DEBUG\n";
#endif
std::cout << "Hello World" << std::endl;
}
Then a bit of UNIX knowledge to run this on all files:Code:sed -e'/^#ifdef *_DEBUG/,/^#endif/d' <filename>
Warning though: This is simple line matching, so if you have a nested #ifdef/#endif within the debug code, this will fail.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
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.