what is file scope?

V

Vipul Jain

Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.

Vipul
 
V

Victor Bazarov

Vipul Jain said:
Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.

None whatsoever.
 
U

Unforgiven

E. Robert Tisdale said:
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).
 
D

David Harmon

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[/QUOTE]

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.
 
E

E. Robert Tisdale

David said:
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.
 
V

Victor Bazarov

E. Robert Tisdale said:
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
 
E

E. Robert Tisdale

Victor said:
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.
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.
 
D

David Harmon

On Sun, 26 Sep 2004 18:27:57 -0700 in comp.lang.c++, "E. Robert Tisdale"
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top