avatar
Help!! variable scope ????# Programming - 葵花宝典
c*n
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
avatar
N*r
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(){

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。