so库中定义的同名全局变量

Nee*_*tal 5 c linux shared-libraries

我想知道以下场景中的行为:-

//file1.c : Main file of a user-space process,say Process X.
int a; //GLobal variable in file1.c
func(); //Library function

//file2.c :Part of .so used by Process X.
int a;
void func()
{
    a=0;//Access variable a.
}
Run Code Online (Sandbox Code Playgroud)

如果 Process X 调用func()库的函数,会发生什么?

Jas*_* Hu 0

进行测试。太简单。

file2 中的 a 与 func 链接,因此 file1 中的 a 不会受到影响。它们是不同的两个变量。