Odd problem to debug

Started by
2 comments, last by zaidgs 20 years ago
i have this really nasty problem. my program crashes telling me: Stack Overflow. the problem is: (1) the call stack has only few functions. (2) it occurs even BEFORE THE PROGRAM STARTS my code looks something like this: #include "ManyThings.h" int main() { //the problem occurs on this line //somewhere out of my code //where the program is getting //ready to start int x=0; //NOT even this one, it crashes before this line. long y=10; myClass1 z; myClass2 w; //rest of the program return 0; } i noticed one interesting thing, that might help clear out something to someone !!! when commenting the definition of "w", (ie. type myClass2) the problem is gone. .... myClass1 z; //myClass2 w; .... i DONT even have to remove the "myClass2.h" file. NO warnings or errors are issued during builds. this happens BEFORE even calling the myClass2 constructor!! if you put a breakpoint on the "" int main(){ "", the program breaks, but when you place the breakpoint on the next line ( "" int x=0; "" ) it crashes before the breakpoint!!! whats wrong ????!! [edited by - zaidgs on April 10, 2004 4:33:46 PM]
Advertisement
Put the breakpoint on the MyClass2 constructor. Creation order of statically-allocated variables at the same scope may not be guaranteed by the standard, so it could be a failure within the MyClass2 ctor.
If you do sizeof(myClass2), what do you get? If myClass2 is sufficiently large, it will crack the stack even before the class constructor is reached. Which yields several solutions: put it on the heap instead, make it smaller, put it''s members on the heap intead, and so on.
the class constructor is not even called.

SiCrane's suggestion is absolutely right:
sizeof(MyClass2)=23520008 !!!
so big.
i tried to make its size smaller,
(i decreased the bounds of one array)
and yeah, it worked !!!!

thanks SiCrane.

still i have used this class in other applications
without a problem. (one MFC, another Dll)
this one is console application,
could that have caused the problem ?!?!
is it that a console aplication is more
limited on stack space ?!?!
(just want to make my knowledge better,
as my problem is resolved )

[edited by - zaidgs on April 11, 2004 12:24:53 PM]

This topic is closed to new replies.

Advertisement