Jump to content
  • Advertisement
Sign in to follow this  
Unconquerable

Stopping execution in C++

This topic is 4607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
The usual way to shut down the program is to return from main. ;-)
You can also call exit, but if I recall correctly, it's not guaranteed to call destructors and probably isn't a good idea.

Share this post


Link to post
Share on other sites
exit() will call destructors of global objects, but not necessarily local objects currently on the stack. It's a perfectly fine way to exit a process.

abort() won't call any destructors, but also will likely generate a crash dump or user message of some sort.

The easiest way is to wrap a big try/catch around your main, and throw something like a quit_exception from within your code; have it caught in the main function and return your status code to the OS.

Share this post


Link to post
Share on other sites
There was a discussion on this a while ago...

In Win32 the entry code looks something like this:


int ret = main(argc, argv); //same for WinMain(...);
exit(ret);


So there is nothing to worry about except calling destructors.

Share this post


Link to post
Share on other sites
Quote:
Original post by Beer Hunter
The usual way to shut down the program is to return from main. ;-)


QFE. Why do you think this won't work in your situation?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!