- 静态链接的处理 - 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;
}