2011-10-10 54 views
0

编译源在我的C++文件,我有任何脚本来剔除在C++

#ifdef DEBUG 
    then blah 
#else 
    blooh. 

我想去掉不经过预处理,这样,如果DEBUG没有定义被编译,所有的文字,那么表格中的所有声明:

#ifdef DBUG 
    /* some debug code */ 
#endif 

被剥离出来。

编辑:下面是一个例子:

#include <iostream> 
//#define DEBUG 
int main(){ 
    #ifdef DEBUG 
     cout << "In debug\n"; 
    #endif 
    cout << "hello\n"; 
    return 0; 
} 

和运行脚本后,输出应该是

#include <iostream> 
//#define DEBUG 
int main(){ 
    cout << "hello\n"; 
return 0; 
} 
+3

心不是预处理器做什么? – slartibartfast

+1

不,我想OP不希望替换'#define'd符号,评估其他'#ifdef',插入'#include'等。 –

回答

2

只是运行预处理不够好?例如g++ -E

+0

我刚刚尝试过,但它也生成stl的代码。为了更清楚我只想要没有stl生成的代码的相同的CPP,但只是#ifdef下的代码被剥离了。 – dchhetri

1

只要用适当的定义运行你的编译器的预处理器。在Windows上,这将是cl /EP file和Linux gcc -E。最有可能的是,你必须通过你的定义,使用-DFoo

0

预处理器执行此操作。

您可以使用g++ -E somefile.cpp来查看它生成的内容。