473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 22 '05 #1
9 5891
"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
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
"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
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
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2171
by: Kobu | last post by:
The code below isn't compiling for me (error message: conflicting types for 'total' - pointing to the extern declaration). Why wouldn't this work, since the types are different, the extern...
1
1508
by: jun qu | last post by:
I just make my first C# test application, my question is what file such as DLL need along with this exe, when install exe at another computer. Thanks
165
6745
by: Dieter | last post by:
Hi. In the snippet of code below, I'm trying to understand why when the struct dirent ** namelist is declared with "file" scope, I don't have a problem freeing the allocated memory. But...
9
19117
by: Quiver | last post by:
Is there a way to have the user choose what file to import, but set everything else up in VBA? The command button that would start the import would have something like this -- ...
1
1489
by: Chris Fairles | last post by:
Possible? Take the following example: =================== //test1.hpp namespace B { typedef int type; void foo() {} } =================== //test.hpp
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.