c******n 发帖数: 4965 | 1 I think I read somewher before that
the scopes of global variables in C are not cleanly defined
if you have multiple definitions of a variable in different files,
some compilers take them to be "static", some take as "global"
e.g. I have a.c, and b.c
////////////////////////////
// a.c
int n;
void fun();
void main(){
n=1;
fun();
printf("main: %d\n", n);
}
//////////////
// b.c
int n;
void fun(){
n=2;
/////////////////////////////////
// b.c
int n;
void fun(){
n=2;
printf("fun(): %d | N*********r 发帖数: 40 | 2 this is not really the question of scope -- the maxium scope is file scope,
but the question of linkage. Both `n's are of external linkage, so they
are the same variable.
【在 c******n 的大作中提到】 : I think I read somewher before that : the scopes of global variables in C are not cleanly defined : if you have multiple definitions of a variable in different files, : some compilers take them to be "static", some take as "global" : e.g. I have a.c, and b.c : //////////////////////////// : // a.c : int n; : void fun(); : void main(){
|
|