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 

Terminology - global

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





PostPosted: Thu Feb 24, 2005 4:26 pm    Post subject: Terminology - global Reply with quote



Stroustrup 3rd edition, 4.9.4, 2nd paragraph:
"A name is called global if it is declared outside any function, class
(Chapter 10), or namespace. The scope of a global name extends from the
point of declaration to the end of the file in which its declaration
occurs."

Is x in the following global?

// Start of a file
static const int x = 0;
class MyClass
{
//etc.

I know such usage is deprecated (ref: B.2.3 in the above).

Back to top
Victor Bazarov
Guest





PostPosted: Thu Feb 24, 2005 4:40 pm    Post subject: Re: Terminology - global Reply with quote



bob wrote:
Quote:
Stroustrup 3rd edition, 4.9.4, 2nd paragraph:
"A name is called global if it is declared outside any function, class
(Chapter 10), or namespace. The scope of a global name extends from the
point of declaration to the end of the file in which its declaration
occurs."

Is x in the following global?

// Start of a file
static const int x = 0;
class MyClass
{
//etc.

I know such usage is deprecated (ref: B.2.3 in the above).


Yes, it is global in the sense used in the quote you presented.

I am more used to a small correction (or addition) to that definition.
A name defined outside of any function, class, or namespace, _and_ has
external linkage. That makes it really global, i.e. visible from other
translation units.

However, the quote you gave is in the section that talks about scope,
about name hiding, and about the ways to access global names using the
scope resolution operator (:Smile, so linkage is not involved.

V

Back to top
bob
Guest





PostPosted: Thu Feb 24, 2005 5:36 pm    Post subject: Re: Terminology - global Reply with quote



Thanks Victor.
This was provoked by a code review at my place of employment.
The code snippet was:

// Local
static const int x = 0;
class { etc.

I objected to the "Local" comment (and the fact that such usage is
deprecated).
Believe it or not, this lead to about 5 email exchanges.
The problem is semantics as you pointed out:
There is "global" and "really global".
The term "global" (ala Stroustrup) is overloaded in the sense that it
can refer to either meaning. I think many/most programmers use the
"really global" interpretation and thus the "Local" comment in the code
snippet.
Bob.

Back to top
Alf P. Steinbach
Guest





PostPosted: Thu Feb 24, 2005 5:45 pm    Post subject: Re: Terminology - global Reply with quote

* bob:
Quote:
Thanks Victor.
This was provoked by a code review at my place of employment.
The code snippet was:

// Local
static const int x = 0;
class { etc.

I objected to the "Local" comment (and the fact that such usage is
deprecated).
Believe it or not, this lead to about 5 email exchanges.
The problem is semantics as you pointed out:
There is "global" and "really global".
The term "global" (ala Stroustrup) is overloaded in the sense that it
can refer to either meaning. I think many/most programmers use the
"really global" interpretation and thus the "Local" comment in the code
snippet.

One alternative is to use a word such as "private". Of course that's
overloaded too. Any way, the comment above is like this one:

a = b + c; // Compute the sum of b and c, and assign that to a.

If someone doesn't know what "static" means, then that someone has
no business maintaining the code.

So I agree, the comment was a bad 'un (I also agree with Victor about
the usual interpretation of "global", and there are more).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to top
Daniel Lidström
Guest





PostPosted: Thu Feb 24, 2005 5:47 pm    Post subject: Re: Terminology - global Reply with quote

On Thu, 24 Feb 2005 09:36:45 -0800, bob wrote:

Quote:
There is "global" and "really global".
The term "global" (ala Stroustrup) is overloaded in the sense that it
can refer to either meaning. I think many/most programmers use the
"really global" interpretation and thus the "Local" comment in the code
snippet.

How can the variable be made "really" global?

--
Daniel


Back to top
Victor Bazarov
Guest





PostPosted: Thu Feb 24, 2005 6:12 pm    Post subject: Re: Terminology - global Reply with quote

Daniel Lidström wrote:
Quote:
On Thu, 24 Feb 2005 09:36:45 -0800, bob wrote:


There is "global" and "really global".
The term "global" (ala Stroustrup) is overloaded in the sense that it
can refer to either meaning. I think many/most programmers use the
"really global" interpretation and thus the "Local" comment in the code
snippet.


How can the variable be made "really" global?

If you look at the original post and my reply, the variable in question
was declared 'static' which meant it had internal linkage. It is also
const, which gives it even more internal linkage (if that's possible).
To make it "really global" in *my* meaning of "global", it had to be
declared 'extern', which along with the initialiser would give it external
linkage while defining it in this module:

extern const int x = 0;

Now, 'x' is visible from other translation units. If in another module
you declare it

extern const int x;

then the symbol will be resolved during linking.

V

Back to top
Howard
Guest





PostPosted: Thu Feb 24, 2005 8:41 pm    Post subject: Re: Terminology - global Reply with quote


"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote

Quote:
Daniel Lidstrvm wrote:
On Thu, 24 Feb 2005 09:36:45 -0800, bob wrote:


There is "global" and "really global".
The term "global" (ala Stroustrup) is overloaded in the sense that it
can refer to either meaning. I think many/most programmers use the
"really global" interpretation and thus the "Local" comment in the code
snippet.


How can the variable be made "really" global?

If you look at the original post and my reply, the variable in question
was declared 'static' which meant it had internal linkage. It is also
const, which gives it even more internal linkage (if that's possible).
To make it "really global" in *my* meaning of "global", it had to be
declared 'extern', which along with the initialiser would give it external
linkage while defining it in this module:

extern const int x = 0;

Now, 'x' is visible from other translation units. If in another module
you declare it

extern const int x;

then the symbol will be resolved during linking.

V

Why do you need the "extern" where it's defined... because it's a const?
For variables that are not const, the extern specifier is only needed in the
"other" modules, correct?

-Howard



Back to top
Victor Bazarov
Guest





PostPosted: Thu Feb 24, 2005 8:47 pm    Post subject: Re: Terminology - global Reply with quote

Howard wrote:
Quote:
[..]
Why do you need the "extern" where it's defined... because it's a const?
For variables that are not const, the extern specifier is only needed in the
"other" modules, correct?

Yes, both correct.

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.