| View previous topic :: View next topic |
| Author |
Message |
Vipul Jain Guest
|
Posted: Sat Sep 25, 2004 9:17 pm Post subject: what is file scope? |
|
|
Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.
Vipul
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Sun Sep 26, 2004 1:08 am Post subject: Re: what is file scope? |
|
|
"Vipul Jain" <vipulsj (AT) yahoo (DOT) com> wrote...
| Quote: | Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.
|
None whatsoever.
|
|
| Back to top |
|
 |
E. Robert Tisdale Guest
|
Posted: Sun Sep 26, 2004 1:13 am Post subject: Re: what is file scope? |
|
|
Vipul Jain wrote:
| Quote: | Can any one please tell me what is the difference
between global scope and file scope of an variable.
cat file.cc
int a = 0; // global scope |
static
int b = 0; // file scope
|
|
| Back to top |
|
 |
Unforgiven Guest
|
Posted: Sun Sep 26, 2004 4:39 pm Post subject: Re: what is file scope? |
|
|
"E. Robert Tisdale" <E.Robert.Tisdale (AT) jpl (DOT) nasa.gov> wrote
| Quote: | Vipul Jain wrote:
Can any one please tell me what is the difference between global scope
and file scope of an variable.
cat file.cc
int a = 0; // global scope
static
int b = 0; // file scope
|
I don't agree with that. The way I was tought it scope deals only with
visibility of a name in code. Without extra help (an extern declaration),
"a" is visible only within the translation unit file.cc, so it has file
scope. As such, true global scope doesn't exist in C++, and the term global
scope is frequently used to refer to file scope. So as Victor said, there is
no difference.
According to the terminology I know, "a" has external linkage and "b" has
internal linkage, but they both have the same scope (file) and lifetime
(application).
--
Unforgiven
|
|
| Back to top |
|
 |
David Harmon Guest
|
Posted: Sun Sep 26, 2004 5:04 pm Post subject: Re: what is file scope? |
|
|
On Sat, 25 Sep 2004 18:13:16 -0700 in comp.lang.c++, "E. Robert Tisdale"
<E.Robert.Tisdale (AT) jpl (DOT) nasa.gov> wrote,
| Quote: | Vipul Jain wrote:
Can any one please tell me what is the difference
between global scope and file scope of an variable.
cat file.cc
int a = 0; // global scope
static
int b = 0; // file scope
|
Sorry, there is no difference in scope between those two. The names
"a" and "b" are both introduced into the scope in which the declarations
occur.
In a namespace scope (including the global namespace scope), those
declarations illustrate the difference between internal linkage and
external linkage.
In a block scope, those declarations illustrate the difference between
automatic storage duration and static storage duration.
I think Victor had the correct answer.
|
|
| Back to top |
|
 |
E. Robert Tisdale Guest
|
Posted: Sun Sep 26, 2004 10:49 pm Post subject: Re: what is file scope? |
|
|
David Harmon wrote:
| Quote: | E. Robert Tisdale wrote:
Vipul Jain wrote:
Can any one please tell me what is the difference
between global scope and file scope of an variable.
cat file.cc
int a = 0; // global scope
static
int b = 0; // file scope
Sorry, there is no difference in scope between those two. The names
"a" and "b" are both introduced into the scope in which the declarations
occur.
In a namespace scope (including the global namespace scope), those
declarations illustrate the difference between internal linkage and
external linkage.
In a block scope, those declarations illustrate the difference between
automatic storage duration and static storage duration.
I think Victor had the correct answer.
|
I'm sure that you and Victor have the correct answer to some question
but I don't think that was the distinction
that Vipul Jain was looking for.
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Sep 27, 2004 1:11 am Post subject: Re: what is file scope? |
|
|
"E. Robert Tisdale" <E.Robert.Tisdale (AT) jpl (DOT) nasa.gov> wrote...
| Quote: | David Harmon wrote:
E. Robert Tisdale wrote:
Vipul Jain wrote:
Can any one please tell me what is the difference between global scope
and file scope of an variable.
cat file.cc
int a = 0; // global scope
static
int b = 0; // file scope
Sorry, there is no difference in scope between those two. The names "a"
and "b" are both introduced into the scope in which the declarations
occur.
In a namespace scope (including the global namespace scope), those
declarations illustrate the difference between internal linkage and
external linkage.
In a block scope, those declarations illustrate the difference between
automatic storage duration and static storage duration.
I think Victor had the correct answer.
I'm sure that you and Victor have the correct answer to some question
but I don't think that was the distinction
that Vipul Jain was looking for.
|
I suppose you have a working crystal ball then, since you definitely knew
that the OP wanted to know about linkage and not scope. I just can't
imagine that it was you who confused them...
V
|
|
| Back to top |
|
 |
E. Robert Tisdale Guest
|
Posted: Mon Sep 27, 2004 1:27 am Post subject: Re: what is file scope? |
|
|
Victor Bazarov wrote:
| Quote: | I suppose you have a working crystal ball then,
since you definitely knew that
the OP wanted to know about linkage and not scope.
|
I knew no such thing.
But I do know what C and C++ programmers usually mean
when they say "global scope" and I think that you do too.
| Quote: | I just can't imagine that it was you who confused them...
|
Oh, let's just pretend that I'm confused and *not* Vipul Jain.
Please elaborate for *me*
the difference between scope and linkage.
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Sep 27, 2004 2:09 am Post subject: Re: what is file scope? |
|
|
"E. Robert Tisdale" <E.Robert.Tisdale (AT) jpl (DOT) nasa.gov> wrote...
| Quote: | Please elaborate for *me*
the difference between scope and linkage.
|
Get a copy of the Standard and study it.
|
|
| Back to top |
|
 |
David Harmon Guest
|
Posted: Mon Sep 27, 2004 4:48 am Post subject: Re: what is file scope? |
|
|
On Sun, 26 Sep 2004 18:27:57 -0700 in comp.lang.c++, "E. Robert Tisdale"
<E.Robert.Tisdale (AT) jpl (DOT) nasa.gov> wrote,
| Quote: | Please elaborate for *me* the difference between scope and linkage.
|
An identifier that can be referred to as ::identifier is in the global
scope (AKA global namespace scope.) You have already shown how such an
identifier can have internal or external linkage.
|
|
| Back to top |
|
 |
|