too much globals?

G

Gernot Frisch

Hi,

I have a program that runs perfectly under win32. But under WinCE it
fails to start (of course compiled for WinCE). It doesn't even reach
the winmain. So far OT, but the problem is - the only difference is
the number of functions and global variables I added to a version that
runs perfectly on both. Although some variables (in both cases) are
classes that have constructors (which are evaluated before main,
right?). Is there any limit of global variables? How can I avoid this
problem - or better: How can I check where it comes from?
My string class e.g. has:
class MyString
{
public:
char data[512];
}

And I have a lot of them...


Thank you in advice.
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
J

John Harrison

Hi,

I have a program that runs perfectly under win32. But under WinCE it
fails to start (of course compiled for WinCE). It doesn't even reach
the winmain. So far OT, but the problem is - the only difference is
the number of functions and global variables I added to a version that
runs perfectly on both. Although some variables (in both cases) are
classes that have constructors (which are evaluated before main,
right?). Is there any limit of global variables? How can I avoid this
problem - or better: How can I check where it comes from?
My string class e.g. has:
class MyString
{
public:
char data[512];
}

And I have a lot of them...


Thank you in advice.

It seems quite likely you run into the "static initialization order
fiasco" (Marshall Cline's words not mine). Check the FAQ question #10.11
and following.

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.11

But if that doesn't sound like it then yes maybe you have hit some limit
on the size of global variables, but any such limit would be imposed by
your compiler and operating system not by C++.

I'd bet on the former however.

john
 
J

John Harrison

It seems quite likely you run into the "static initialization order
fiasco" (Marshall Cline's words not mine). Check the FAQ question #10.11
and following.

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.11

john

Reading the FAQ for myself I'm not sure it emphasises sufficiently that
one way to avoid initialisation order problems is to put all your global
variables in a single source file. That way the order of initialisation is
defined, its the same as the order that the globals occur in the file.

john
 
W

Wiseguy

Gernot Frisch said:
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}


no return value? and in a group devoted to proper c++ usage? shame!
 
G

Gernot Frisch

no return value? and in a group devoted to proper c++ usage?
shame!

Doh! Sorry. I'll fix that. Thank you.
 
G

Gernot Frisch

no return value? and in a group devoted to proper c++ usage?
No don't. Strangely the C++ standard does not require a return value from
main.

Oh...er... Yes, that was exaclty what I wanted to say - "learn the
standard before you flame me - you yaddayadda" ;)
 
J

John Harrison

Gernot Frisch said:
shame!

Doh! Sorry. I'll fix that. Thank you.

No don't. Strangely the C++ standard does not require a return value from
main.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top