This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

B19: problem initialising global objects


hello,

i'm using b19 with egcs1.0.2 on NT4.0.
while porting a program which works fine with egcs1.02 under linux,
i encountered big problems under cygwin32.
it seems to me that global objects (such as for example static class
members)
don't get initialised properly before program start.

take for example the following short program :
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
class Bug {
public:
  Bug() { cout << "Bug() constructed" << endl; }
};
int main() {
Bug BUG;
}
////////////////////////////////////////////////////////////////////////////////

it works perfectly fine and prints out :
> Bug() constructed

But if we make BUG a globale variable by moving it outside
of main, like in the following example :
/////////////////////////////////////////////////////////////////////////////////////

#include <iostream>
class Bug {
public:
  Bug() { cout << "Bug() constructed" << endl; }
};
Bug BUG;
int main() {
}
/////////////////////////////////////////////////////////////////////////////////////

we get a perfect segmentation fault, saying :

> Exception: STATUS_ACCES_VIOLATION

with gdb we can localize the error to happen in  :
---------------------------------------------------------------------------

ostream::operator<< (this=0x41100c, s=0x401040 "Bug() constructed") at
libio/iostream.cc:784
----------------------------------------------------------------------------

it seems to me that cout has not been initialized properly before the
initialisation
of BUG where it is used. Is this true ?

as i have a lot of static and global objects with complex constructors,
this
is a big problem for me.

does anybody know the exact reason of this error an possible workarounds
?
any information appreciated.

volker



-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]