Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1772412
  • 博文数量: 272
  • 博客积分: 1272
  • 博客等级: 少尉
  • 技术积分: 1866
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-09 15:51
文章分类

全部博文(272)

文章存档

2016年(16)

2015年(28)

2014年(97)

2013年(59)

2012年(25)

2011年(47)

分类: C/C++

2014-03-24 10:43:02

原文地址:gcc -D:gcc的预定义功能 作者:yishuihe

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

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