一个projects里查找到底有多少个宏在编译时生效,多少个开关是打开的
可在ifdef等后面添加一行#warning,使得编译过程中以warning的形式打印出来,当然gcc不要打开Werror选项,否则都作为error了
进而可通过模式匹配得到相应的defined的开关
lihui@LastWish ~ $ cat define.c
#include <stdio.h>
#if defined(HELLO)
#warning HELLO is defined
#elif defined(WORLD)
#warning WORLD is defined
#endif
int main(){
return 0;
}
lihui@LastWish ~ $ gcc define.c -DHELLO
define.c:4:2: warning:#warning HELLO is defined [-Wcpp]
lihui@LastWish ~ $ gcc define.c -DWORLD
define.c:6:2: warning:#warning WORLD is defined [-Wcpp]