由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - [转载] Help!! variable scope ????
相关主题
请教两道问题,谢谢[公告] CompSci 板的投票结果
请教Ubuntu 11.10下安装OpenCV2.3.1建议用open64Re: 改GCC 弄出一个特殊的Compiler,可能吗?
C# + SQL 是叫什么来着?GCC compiler 的问题
没找到php的板块,php extension c++遇到点麻烦NP-complete problem collection
Java怎么不能用新的版本编译?Re: [转载] difference:HTTP 200 OK and 201
how to define variables on commnad line in C++SPAM 2.0
CPU 支持操作系统的问题 (转载)[转载] 问个fortran的基础问题
HOW TO SOLVE THIS EQUATION?An interview question
相关话题的讨论汇总
话题: variable话题: scope话题: void话题: fun话题: global
进入CS版参与讨论
1 (共1页)
c******n
发帖数: 4965
1
【 以下文字转载自 Programming 讨论区 】
【 原文由 creation 所发表 】
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;
/////////////////////////////////
f*****p
发帖数: 235
2
Why not just try it out.

【在 c******n 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 creation 所发表 】
: 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;

c******n
发帖数: 4965
3
of course I know the results
just want to know the standards / or lack thereof

【在 f*****p 的大作中提到】
: Why not just try it out.
f*****p
发帖数: 235
4
No idea. If this is an interview question, it's bad.

【在 c******n 的大作中提到】
: of course I know the results
: just want to know the standards / or lack thereof

c******n
发帖数: 4965
5
I always use
extern/static for sure,

【在 f*****p 的大作中提到】
: No idea. If this is an interview question, it's bad.
f*****p
发帖数: 235
6
if u sure, why post?

【在 c******n 的大作中提到】
: I always use
: extern/static for sure,

c******n
发帖数: 4965
7
it's still allowable by standards!
many people write such code

【在 f*****p 的大作中提到】
: if u sure, why post?
v******d
发帖数: 1322
8
if u don't use extern, u cannot access the global
variable defined in the other files.

【在 c******n 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 creation 所发表 】
: 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;

c******n
发帖数: 4965
9
just try my example with gcc

【在 v******d 的大作中提到】
: if u don't use extern, u cannot access the global
: variable defined in the other files.

1 (共1页)
进入CS版参与讨论
相关主题
An interview questionJava怎么不能用新的版本编译?
编译书一问how to define variables on commnad line in C++
推荐一个open source的c compilerCPU 支持操作系统的问题 (转载)
How is this conference?HOW TO SOLVE THIS EQUATION?
请教两道问题,谢谢[公告] CompSci 板的投票结果
请教Ubuntu 11.10下安装OpenCV2.3.1建议用open64Re: 改GCC 弄出一个特殊的Compiler,可能吗?
C# + SQL 是叫什么来着?GCC compiler 的问题
没找到php的板块,php extension c++遇到点麻烦NP-complete problem collection
相关话题的讨论汇总
话题: variable话题: scope话题: void话题: fun话题: global