| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs> |
| 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 <sc AT axlog DOT fr> |
| 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 <emild AT cs DOT Technion DOT AC DOT IL> |
| Subject: | Re: g++/static members/DLL problem |
| References: | <Pine DOT GSO DOT 4 DOT 33_heb2 DOT 09 DOT 0203112307170 DOT 22729-100000 AT 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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |