Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4536202
  • 博文数量: 1214
  • 博客积分: 13195
  • 博客等级: 上将
  • 技术积分: 9105
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-19 14:41
个人简介

C++,python,热爱算法和机器学习

文章分类

全部博文(1214)

文章存档

2021年(13)

2020年(49)

2019年(14)

2018年(27)

2017年(69)

2016年(100)

2015年(106)

2014年(240)

2013年(5)

2012年(193)

2011年(155)

2010年(93)

2009年(62)

2008年(51)

2007年(37)

分类: C/C++

2010-11-30 22:37:09

一、 介绍预定义宏“__GNUC__”

        一.1 __GNUC__ 是gcc编译器编译代码时预定义的一个宏。

需要针对gcc编写代码时, 可以使用该宏进行条件编译。

        一.2 __GNUC__ 的值表示gcc的版本。

需要针对gcc特定版本编写代码时,也可以使用该宏进行条件编译。

        一.3 __GNUC__ 的类型是“int”

该宏被扩展后, 得到的是整数字面值
可以通过仅预处理,查看宏扩展后的文本。见:《查看源文件预处理结果
同时下面的示例也能体现出这一点。



二、 测试预定义宏__GNUC__

示例:
#include <assert.h>
#include 
<stdio.h>
#include 
<typeinfo>

#ifndef __GNUC__
#error sample for gcc compiler
#else
/* use gcc special extension: #warning , __attribute__, etc.  */
#endif

int main() {
    printf(
"hello gcc %d\n",__GNUC__);
    assert( typeid(__GNUC__)
==typeid(int) );
    printf(
"press Enter to exit\n");
    (
void)getchar();
}




修改:

——2009/04/18

__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__
These macros are defined by all GNU compilers that use the C preprocessor:
C, C++, and Objective-C. Their values are the major version, minor version,
and patch level of the compiler, as integer constants. For example, GCC 3.2.1
will define __GNUC__ to 3, __GNUC_MINOR__ to 2, and __GNUC_PATCHLEVEL__ to
1. They are defined only when the entire compiler is in use; if you invoke the
preprocessor directly, they are not defined.

      —— 


相关链接:

——源代码


——《查看源文件预处理结果》
http://www.cppblog.com/ownwaterloo/archive/2009/04/16/get_result_of_preprocessing.html

——《预定义_MSC_VER宏》
http://www.cppblog.com/ownwaterloo/archive/2009/04/15/predefined_macro__MSC_VER.html




  
作品采用进行许可。 

转载请注明 :
文章作者 - OwnWaterloo
发表时间 - 2009年04月16日
原文链接 - http://www.cppblog.com/ownwaterloo/archive/2009/04/16/predefined_macro___GNUC__.html

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