Re: Hep
On 21 mai, 19:02, Christopher <cp...@austin.rr.com> wrote:
On May 21, 4:15 am, Manmeet <mannir...@gmail.com> wrote:
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.
Globals and Statics have scope of the module they are defined
in. i.e. The .dll or library that defines them.
Nonsense.
First, don't confuse scope with lifetime or linkage. A
declaration has scope, not a variable. And whether declarations
of the same name in different places refers to the same object
or not depends on linkage.
And finally, whether the object file is part of a library or not
is totally irrelevant to the question.
They can also be exported to be visible outside the module
(keyword export).
The keyword export only applies to templates, and isn't
implemented by a lot of compilers.
Your problem is most likely that in C++ the order of
initialization and destruction for globals and statics is
undefined.
Possibly. Alternatively, it's possible that he's built or is
loading the dynamic libraries in a way that causes the variable
to be defined more than once; he might start by outputting its
address. (This is, of course, very much outside the scope of
C++, which doesn't say much of anything about how dynamic
linking works. Unix has a number of options so that its
behavior can be controlled by the programmer; I believe Windows
does as well, with the difference that under Windows, the
options are link-time, where as under Unix, they are at least
partially runtime. At any rate, it's a very platform dependent
issue.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34