Skip to content

Latest commit

 

History

History
26 lines (25 loc) · 414 Bytes

27 | 编译器在链接程序时发生了什么?.md

File metadata and controls

26 lines (25 loc) · 414 Bytes
  • 静态链接的处理 - 0x1:
// main.c
#define LEN 2
extern int sharedArr[LEN];
extern int sum(int *arr, int n);
int* array = sharedArr;
int main(void) {
  int val = sum(array, LEN);
  return val;
}
  • 静态链接的处理 - 0x2:
// sum.c
#define LEN 2
int sharedArr[LEN] = { 1, 2 };
int sum(int *arr, int n) {
  int i, s = 0;
  for (i = 0; i < n; i++) {
    s += arr[i];
  }
  return s;
}