By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

what is file scope?

P: n/a
Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.

Vipul
Jul 22 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Vipul Jain" <vi*****@yahoo.com> wrote...
Can any one please tell me what is the difference between global
scope of an variable and file scope of an variable.


None whatsoever.
Jul 22 '05 #2

P: n/a
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
Jul 22 '05 #3

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:cj**********@nntp1.jpl.nasa.gov...
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
Jul 22 '05 #4

P: n/a
On Sat, 25 Sep 2004 18:13:16 -0700 in comp.lang.c++, "E. Robert Tisdale"
<E.**************@jpl.nasa.gov> 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.
Jul 22 '05 #5

P: n/a
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.
Jul 22 '05 #6

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote...
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
Jul 22 '05 #7

P: n/a
Victor Bazarov wrote:
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.
Jul 22 '05 #8

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote...
Please elaborate for *me*
the difference between scope and linkage.


Get a copy of the Standard and study it.
Jul 22 '05 #9

P: n/a
On Sun, 26 Sep 2004 18:27:57 -0700 in comp.lang.c++, "E. Robert Tisdale"
<E.**************@jpl.nasa.gov> wrote,
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.
Jul 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.