473,663 Members | 2,694 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 5907
"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.na sa.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
2180
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 declaration obviously refers to the 'long total' in total.c? Is my compiler wrong? total.c
1
1515
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
6830
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 when the struct is declared in main (block scope) it will segfault when passing namelist to freeFileNames().
9
19145
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 -- DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, "tblMAIN",???,True -- with the ??? indicating where you would typically put the path and name of the spreadsheet. However, the spreadsheet that will be imported will have a variable name including the...
1
1501
by: Chris Fairles | last post by:
Possible? Take the following example: =================== //test1.hpp namespace B { typedef int type; void foo() {} } =================== //test.hpp
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.