gcc与__cplusplus宏

来源:互联网 发布:淘宝店铺装修招牌图片 编辑:程序博客网 时间:2024/06/05 11:43

                     __cplusplus宏标志编译器会把代码按C还是C++语法来解析,gcc是没有定义改宏的,而g++却定义了。

[xxx@localhost test]$ [mapan@localhost test]$ lstest.c[xxx@localhost test]$ cat test.c #include<stdio.h>#ifdef __cplusplusint a=1;#endifint 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 oncetest.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]$ 

结果一目了然。


原创粉丝点击