Jump to content
  • Advertisement
Sign in to follow this  
darenking

Exiting/ending a program in C++ - SOLVED

This topic is 4869 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

Hello, I know I can end a program at any time in the main() function just by putting return 0; But what if I want to end a program from within another function or within a class method? In BlitzBasic you can just put End at any point in any function. Hmm... [Edited by - joebarnslondon on June 17, 2005 5:42:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by daviangel
http://www.cplusplus.com/ref/cstdlib/exit.html
you should have a good reason for using this!


Thanks for that. Is there any particular reason why it is not a good idea to use it?

Share this post


Link to post
Share on other sites
I want to add there is bad habbit using not-well-structured programs.and gotos and exits popping up all around the place fall in this category.
anyway,be sure to use atexit to free/delete all heap-allocated space

Share this post


Link to post
Share on other sites
Quote:
Original post by DevLiquidKnight
I don't think theres any cause for concern to not use it, unless you maybe allocated memory using the new operator and never deleted it.


The operating system should clean up that when you exit. More to the matter at hand, why don't you use exceptions for things like that? If you have a fatal error, through a fatal_error exception that's only caught in main which can then exit. This should also clean up all resources used along the way if you coded it properly (raii and such).

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!