This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: g++/static members/DLL problem
- From: Stephane Corbe <sc at axlog dot fr>
- To: cygwin at cygwin dot com
- Cc: Kohn Emil Dan <emild at cs dot Technion dot AC dot IL>
- Date: Tue, 12 Mar 2002 10:24:34 +0000
- Subject: Re: g++/static members/DLL problem
- References: <Pine.GSO.4.33_heb2.09.0203112307170.22729-100000@csd>
Kohn Emil Dan wrote:
> Hello everyone,
>
> I would like to report a problem with g++ static member initialization on
> cygwin. I have a class in which I have a static data member. The
> definition of that class resides in a DLL. That static member is
> initialized in the corresponding .cpp file. However when I access it from
> an application, I do not get the initialized value, instead I get just
> garbage.
>
This is the case for all the global variables (and static members are global).
By the way, it's not a good idea to share other things than pointers,
Dll can shre only pointers. Here you have no warning message because
your variable (int) has the same size than a pointer.
Try to share an object to see.
A solution is to do :
tbar *Foo_bar;
class Foo {
public:
static void init();
static void done();
};
void Foo::init()
{
Foo_bar = new tbar(17);
}
void Foo::done()
{
delete Foo_bar;
}
int main()
{
Foo::init();
printf("Foo::bar=%d\n", *Foo_bar);
Foo::done();
return 0;
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/