C/C++程序编译过程
以hello.c
为例
1 #include <stdio.h>
2
3 int main()
4 {
5 #ifdef __cplusplus
6 printf("cplusplus\n");
7 #endif
8 printf("hello world\n");
9
10 return 0;
11 }
当使用gcc
编译(C
编译器)时,输出:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/df4776d5e11abeb9c7a0bb4805070f03.png)
当使用g++
编译(C++
编译器)时,输出:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1b40dd1cc8304fa597ded90983820eb6.png)
g++编译器定义了_cplusplus
这个宏,而gcc没有。
以上编译过程,都可以分解为如下动作: