|
|
1 gadu atpakaļ | |
|---|---|---|
| .. | ||
| README.md | 1 gadu atpakaļ | |
源码执行的过程可以被分成四部分
# 开始的预编译指令,例如 #include、#define以 hello.c、hello1.c、hello2.c 为例
// hello2.c
int mul(int a, int b){
return a * b;
}
// hello1.c
#include "hello2.c"
int add(int a, int b) {
return a + b;
}
// hello.c
#include "hello1.c"
int main() {
add(1, 2);
return 0;
}
使用命令 gcc -E hello.c -o hello.i,对 hello.c 进行 预处理
# 0 "hello.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 2 "hello.c"
# 1 "hello1.c" 1
# 1 "hello2.c" 1
int mul(int a, int b){
return a * b;
}
# 2 "hello1.c" 2
int add(int a, int b) {
return a + b;
}
# 2 "hello.c" 2
int main() {
add(1, 2);
return 0;
}
#include会递归执行
#define 并展开所有的宏定义#if、#ifdef、#elif、#else、#endif#include 将包含的文件插入到该预编译指令的位置#pragma 编译器指令,编译器要用到使用 gcc -S hello.i -o hello.s 将预处理后的文件编译得到汇编代代码
汇编文件内容较多,不贴代码
使用 gcc -c hello.s -o hello.o 得到机器指令的文件,但是这个文件还不可以执行
在最后执行了链接之后,才能够执行