gcc与__cplusplus宏
作者:互联网
__cplusplus宏标志编译器会把代码按C还是C++语法来解析,gcc是没有定义改宏的,而g++却定义了。
[xxx@localhost test]$
[mapan@localhost test]$ ls
test.c
[xxx@localhost test]$ cat test.c
#include<stdio.h>
#ifdef __cplusplus
int a=1;
#endif
int main()
{
printf("a=%d\n",a);
return 0;
}
[xxx@localhost test]$ gcc test.c
test.c: In function ‘main’:
test.c:9: error: ‘a’ undeclared (first use in this function)
test.c:9: error: (Each undeclared identifier is reported only once
test.c:9: error: for each function it appears in.)
[xxx@localhost test]$ g++ test.c
[xxx@localhost test]$ ./a.out
a=1
[xxx@localhost test]$
结果一目了然。
标签:__,gcc,cplusplus,xxx,error,test,localhost 来源: https://blog.51cto.com/u_15144024/2859968