本节展开CPP的三块核心内容:进程的虚拟地址空间内存划分和布局、函数的调用堆栈详细过程、程序编译链接原理。程序编译链接原理可以参考《深入理解计算机系统》第7章 - 链接、《程序员的自我修养》第2,3,4, 6章。这一部分基础知识除了理解,要练习流畅准确地表达。

进程的虚拟地址空间内存划分和布局

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 定义三个全局变量
int gdata1 = 10;
int gdata2 = 0;
int gdata3;

// 定义三个静态全局变量
static int gdata4 = 11;
static int gdata5 = 0;
static int gdata6;

int main() {

// 定义三个局部变量
int a = 12;
int b = 0;
int c;

// 定义三个静态局部变量
static int e = 13;
static int f = 0;
static int g;

return 0;
}

函数的调用堆栈详细过程

程序编译链接原理