c #if and #ifdef

DON'T USE #if,  because it will cause error " xx is not defined" if you use option "-Werror=undef",  you can use #ifdef XX && XX.

 

using #ifdef XX && XX instead of #if XX to avoid build error with option -Werror=undef

 

BAD:

#if HAVE_SIGNAL_H
#include <signal.h>
#else
#include <sys/signal.h>
#endif

 

GOOD:

#ifdef HAVE_SIGNAL_H && HAVE_SIGNAL_H
#include <signal.h>
#else
#include <sys/signal.h>
#endif

 

这是C++种的条件编译预处理命令
有两种格式:
1:#ifdef 标示符
程序段1
#else
程序段2
#endif
表示:如果标示符已经被#define命令定义过,则编译程序段1,否则编译程序段2
2:#if 表达式
程序段1
#else
程序段2
#endif
表示:如果表达式为真,则编译程序段1,否则编译程序段2.
posted @ 2013-11-22 20:39  alxe_yu  阅读(339)  评论(0)    收藏  举报