We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
In RVMDK3.05, I use simulator to debug C++ code, but it can't run to main function. (Select LPC2292 in "Options for Target" dialog when creating project)
Sample code in test1.cpp as following:
class MYCLASS { public: MYCLASS(){} ~MYCLASS(){} }; MYCLASS myobject; int main() { while (1); return 0; }
If we remove the destructor, it can run to main function. Sample code in test2.cpp as following:
class MYCLASS { public: MYCLASS(){} // ~MYCLASS(){} //remove this line }; MYCLASS myobject; int main() { while (1); return 0; }
Sounds like something that should be reported to Keil support.
A global c++ object should have it's destructor address stored in a specific memory segment, so that the startup code can loop through all destructors after main() returns.
On the other hand, an embedded project is normally not expected to end. There are no command line to return to, so there would normally not be too much use of global object destruction.
In an applications, there would be some local objects and some global objects. Maybe, a local object and a global object have the same class. In this case, does the class need a destuctor?
some local objects and some global objects.
That has nothing to do with it, really. Whether a class needs a destructor depends on the class itself, not on whether its instances are global or local (or rather, of static or non-static storage duration). As a rule of thumb every class should either have one, either explicitly coded or implied by the language.
You are basically talking about the same thing.
In this case, the global object can probably manage without a destructor, since the behaviour of embedded equipment after main() ends is quite interesting anyway...
If the same class is also used for dynamically or stack-allocated objects, then these objects may require that the class has a proper destructor, since they may require that a resource is returned/released on destruct.
Thank you for replying to my question. The problem was resolved. The cause of this problem is that I did not reserve RAM for the Heap.