C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

what is file scope?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Vipul Jain
Guest





PostPosted: Sat Sep 25, 2004 9:17 pm    Post subject: what is file scope? Reply with quote



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





PostPosted: Sun Sep 26, 2004 1:08 am    Post subject: Re: what is file scope? Reply with quote



"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





PostPosted: Sun Sep 26, 2004 1:13 am    Post subject: Re: what is file scope? Reply with quote



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





PostPosted: Sun Sep 26, 2004 4:39 pm    Post subject: Re: what is file scope? Reply with quote

"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





PostPosted: Sun Sep 26, 2004 5:04 pm    Post subject: Re: what is file scope? Reply with quote

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





PostPosted: Sun Sep 26, 2004 10:49 pm    Post subject: Re: what is file scope? Reply with quote

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





PostPosted: Mon Sep 27, 2004 1:11 am    Post subject: Re: what is file scope? Reply with quote

"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





PostPosted: Mon Sep 27, 2004 1:27 am    Post subject: Re: what is file scope? Reply with quote

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





PostPosted: Mon Sep 27, 2004 2:09 am    Post subject: Re: what is file scope? Reply with quote

"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





PostPosted: Mon Sep 27, 2004 4:48 am    Post subject: Re: what is file scope? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.