神创天陆活动专区

[转]预定义__GNUC__宏

一、 介绍预定义宏“__GNUC__” 一.1 __GNUC__ 是gcc编译器编译代码时预定义的一个宏。需要针对gcc编写代码时, 可以使用该宏进行条件编译。 一.2 __GNUC__ 的值表示gcc的版本。需要针对gcc特定版本编写代码时,也可以使用该宏进行条件编译。 一.3 __GNUC__ 的类型是“int”该宏被扩展后, 得到的是整数字面值。可以通过仅预处理,查看宏扩展后的文本。见:《查看源文件预处理结果》同时下面的示例也能体现出这一点。

二、 测试预定义宏__GNUC__示例:#include #include #include #ifndef __GNUC__#error sample for gcc compiler#else/* use gcc special extension: #warning , __attribute__, etc. */#endifint 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.1will define __GNUC__ to 3, __GNUC_MINOR__ to 2, and __GNUC_PATCHLEVEL__ to1. They are defined only when the entire compiler is in use; if you invoke thepreprocessor 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