posts - 16,  comments - 34,  trackbacks - 0

一、 介绍预定义宏“__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://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/Common-Predefined-Macros.html#Common%20Predefined%20Macros


相关链接:

——源代码
http://immature.googlecode.com/svn/trunk/iMmature/sample/predefined_macro/extension/__GNUC__/

——《查看源文件预处理结果》
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




  Creative Commons License
作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

转载请注明 :
文章作者 - OwnWaterloo
发表时间 - 2009年04月16日
原文链接 - http://www.cppblog.com/ownwaterloo/archive/2009/04/16/predefined_macro___GNUC__.html
posted on 2009-04-16 20:07 OwnWaterloo 阅读(9985) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(8)

随笔档案(16)

链接

搜索

  •  

积分与排名

  • 积分 - 194949
  • 排名 - 132

最新随笔

最新评论

阅读排行榜

评论排行榜