首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

请帮小弟我看一下这段代码是什么意思(条件编译的使用)

2012-03-07 
请帮我看一下这段代码是什么意思(条件编译的使用)/*Type:bool*/#ifdefTHINK_Ctypedefintbool#else#ifdefT

请帮我看一下这段代码是什么意思(条件编译的使用)
/*Type:   bool*/

#ifdef   THINK_C
      typedef   int   bool;
#else  
      #ifdef   TRUE              
          #ifdef   bool
              #define   bool   int
        #endif
      #else
          #ifdef   bool
            #define   FALSE   0
            #define   TRUE   1
          #else
            typedef   enum   {FALSE   ,TRUE}   bool;
          #endif
      #endif      
#endif

[解决办法]
这个怎么解释呢 其实和if else 的使用差不多阿
[解决办法]
楼上说的对

编译时
#if 0
//这里面的是不会被编译
#else
//这里面的会被编译
#endif

这种程序适应性强,可以根据配制不同走不同的流程
但是不易读
[解决办法]
#ifdef THINK_C //如果THINK_C在此前已经定义了,
typedef int bool;
#else //否则....
#ifdef TRUE //如果TRUE在此前已经定义了.....
#ifdef bool
#define bool int
#endif
#else
#ifdef bool
#define FALSE 0
#define TRUE 1
#else
typedef enum {FALSE ,TRUE} bool;
#endif
#endif
#endif

每个 #ifdef 与一个#endif相对应!如:
#ifdef 宏替换名
语句段
#endif
表示 如果宏替换名在此前已经由#define语句给出了定义,就编译#ifdef 与一个#endif之间的语句!

热点排行