470,874 Members | 1,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

Hep

Hi,

Problem is regarding the global variables.
I am running an win32 EXE created using VS2005 which in turn use many
DLL's which inturn are using static library (abc.LIB).
Now when I create a global variable in LIB project, it values is
changed( to null )after some point of time.
Does the scope of LIB or DLL has to do with that?
I mean loading and unloading of DLL.
Can anyone guide me on this issue.

Thanks in advance.

Jun 27 '08 #1
4 1242
On May 21, 5:54 am, "Alf P. Steinbach" <al...@start.nowrote:
* Manmeet:
Problem is regarding the global variables.
Can anyone guide me on this issue.

It's simple: avoid global variables.
Use a Singleton instead?
Jun 27 '08 #2
James Kanze wrote:
[..]
First, don't confuse scope with lifetime or linkage. A
declaration has scope, not a variable. [..]
<nitpick>

A *name* has scope. A declaration is an _action_ that defines the scope
[of the name], [because it] happens in a scope, but doesn't *have* it.

A variable is an entity, a way to designate an object by means of a
name. Since a name and a variable are inseparable (a variable cannot
exist without a name), one can extend the statement that a name has
scope to mean that _a variable has scope_. An *object* OTOH does not
have a scope.

I believe that's what you intended to express.

</nitpick>

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #3
On May 21, 11:07 pm, Victor Bazarov <v.Abaza...@comAcast.netwrote:
James Kanze wrote:
[..]
First, don't confuse scope with lifetime or linkage. A
declaration has scope, not a variable. [..]
<nitpick>
A *name* has scope. A declaration is an _action_ that defines
the scope [of the name], [because it] happens in a scope, but
doesn't *have* it.
How right you are. In the end, a declaration is just a
directive to the compiler, telling it to do something. (There
are even some declarations which put the name in another scope;
the definition of a static class member, for example.)
A variable is an entity, a way to designate an object by means
of a name. Since a name and a variable are inseparable (a
variable cannot exist without a name), one can extend the
statement that a name has scope to mean that _a variable has
scope_. An *object* OTOH does not have a scope.
In other words, there are two categories of "objects", those
with names, and those without. Called, respectively, variables
and temporaries. But I don't think it's quite that simple in
C++, since scope is always limited to a single translation unit.
For various historical reasons, C++ distinguishes between scope
and linkage. Practically, it probably is acceptable to consider
external linkage as a "scope" which transcends translation unit
boundaries, provided we stick to the simple cases: the
declaration introduces the name into a more or less limited
scope in a single translation unit, even if the name is
"visible" in other translation units (external linkage). Thus,
for example, in:

void
f()
{
extern int i ;
}

The scope of `i' is limited to the function f, even though it
has external linkage, and an "extern int i ;" declaration in
another translation unit will associate the name i to the same
object.

The way I think of it, informally, is that scope defines the
visibility of a name, whereas linkage is concerned with the
binding of the name to the object (or function or reference).

Arguable, scope, linkage and lifetime are, or should be, more or
less orthogonal. But of course, they way they are specified is
very much linked in C++: scope affects the default lifetime,
even the type (as well as the scope) affects the default
linkage, and the same keyword will sometimes affect one,
sometimes another. If you tried to design something
intentionally to confuse beginners, you could hardly do a better
job of it.
I believe that's what you intended to express.
But didn't, at least not correctly:-).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #4
On May 22, 12:15 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
Victor Bazarov <v.Abaza...@comAcast.netwrites:
James Kanze wrote:
[...]
</nitpick>
To »nitpick« means »to correct minutiae or find fault«
according to »http://en.wiktionary.org/wiki/nitpick«. So by
using »<nitpick>« one emphasizes that one will write someting
(more) correct. This usually is implied even without
»<nitpick>«, but someone who adds »<nitpick>« must be very
sure that he indeed /is/ (more) correct with regard to details.
In everyday use, especially when one uses it referring to one's
own statements, the term is generally understood to mean that
the point being made isn't in anyway essential, and that the
statement being commented was really pretty close to correct to
begin with. In a posting like Victor's, I think it mainly
expresses an intent that the comments shouldn't be taken as a
serious criticism, and that it doesn't raise a fundamental issue
with the original text.

I think Victor actually raised a good point. In C++, at least,
the issues are complex (and in practice, I think this is true of
any language which supports separate compilation), and one
cannot be too precise with regards to the wording used.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.