Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2705573
  • 博文数量: 505
  • 博客积分: 1552
  • 博客等级: 上尉
  • 技术积分: 2514
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-23 18:24
文章分类

全部博文(505)

文章存档

2019年(12)

2018年(15)

2017年(1)

2016年(17)

2015年(14)

2014年(93)

2013年(233)

2012年(108)

2011年(1)

2009年(11)

分类: LINUX

2013-04-07 08:54:03

对付条件编译#if,#ifdef和#if defined这些,穷究 起来照样 有些意思

#if哀求 是一个表达式,为真则推行 以下代码,

#ifdef则只哀求 是否定 义,并不关怀 这个值是什么。

#if defined则是#if和#define的连用。


比如 :

#if 0
/* some code here*/
/* commented */
#endif

#ifdef __MMI_MESSAGES_CLUB__
#include "MessagesResDef.h"
#endif

#if defined( __MMI_IRDA_SUPPORT__ )
#i nclude "ConnectivityResDef.h "
#endif

#if defined还可以串通多个条件:

#if defined( __MMI_MYAPP1_SUPPORT__ ) || defined( __MMI_MYAPP2_SUPPORT__ )
#i nclude "ConnectivityResDef.h "
#endif

还有他们的else用法:

在module.h中有如下定义:

#ifdef CONFIG_X86_64
/* X86_64 does not define MODULE_PROC_FAMILY */
#elif defined CONFIG_M386
#define MODULE_PROC_FAMILY "386 "
#elif defined CONFIG_M486
#define MODULE_PROC_FAMILY "486 "
#else
#define MODULE_STACKSIZE ""
#endif

#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
static struct atmel_nand_data nand_data;
#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
static struct atmel_spi_data spi_data;
#else
void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
#endif

阅读(912) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~