为了阅读代码的方便,通常有两种需求:1)只阅读定义了某种宏的代码;2)只阅读没有定义某个宏的代码.
linux下面提供了unifdef工具.具体安装和使用如下:
-
sudo apt-getinstall unifdef
-
a)获取定义了A的代码:unifdef -DA test.c > modi.c
#ifdef A (去除)
代码块1
#else (去除)
代码块2 (去除)
#endif (去除)
b)去除定义A的代码:unifdef -UA test.c > modi.c
#ifdef A (去除)
代码块1 (去除)
#else (去除)
代码块2
#endif (去除)