预定义__GNUC__宏
1 __GNUC__ 是gcc编译器编译代码时预定义的一个宏。需要针对gcc编写代码时, 可以使用该宏进行条件编译。
2 __GNUC__ 的值表示gcc的版本。需要针对gcc特定版本编写代码时,也可以使用该宏进行条件编译。
3 __GNUC__ 的类型是“int”,该宏被扩展后, 得到的是整数字面值。可以通过仅预处理,查看宏扩展后的文本。
示例:
#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();
}