Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1063263
  • 博文数量: 226
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 2504
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-21 14:12
文章分类

全部博文(226)

文章存档

2011年(1)

2010年(2)

2009年(68)

2008年(4)

2007年(27)

2006年(124)

我的朋友

分类: C/C++

2007-10-22 17:57:29

gcc编译的时候提供了预定义功能,参数是-D,  通过man gcc可以了解更多:
-D name
           Predefine name as a macro, with definition 1.

       -D name=definition
           Predefine name as a macro, with definition definition.  The contents of definition are tokenized and processed as if they appeared during translation phase three in a #define directive.  In particular, the definition will be truncated by embedded new-line characters.

可以通过以下例子解释一下:
int main()
{
    #ifdef HELLO
    printf("HELLO defined\n");
    #else
    printf("HELLO not define\n");
    #endif

    return 0;
}
在该程序中,判断是否已经定义了宏DEBUG,从而输出相应的语句。
如果编译该程序时采用了gcc -DHELLO, 则输出:HELLO defined

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