Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <3C8DD761.91AA72AB@axlog.fr> Date: Tue, 12 Mar 2002 10:24:34 +0000 From: Stephane Corbe X-Mailer: Mozilla 4.7 [en] (X11; I; SunOS 5.8 sun4u) X-Accept-Language: fr, en MIME-Version: 1.0 To: cygwin AT cygwin DOT com Cc: Kohn Emil Dan Subject: Re: g++/static members/DLL problem References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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/