• Advertisement

Archived

This topic is now archived and is closed to further replies.

difference between quit and exit

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

I''m not super knowledgable on C/C++ (obviously) and there is one thing I''m not very sure on. I tried googling for a few minutes and didn''t get any help. What exactly is the difference between the usages of the exit() command and quit() command? --------------------------------------------------- laziness is the foundation of efficiency retrospiral.net | llamas! | megatokyo | gamedev.net | google

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
And, you should probably not be using exit(). There are uses for it, but it is not an "elegant" way to terminate your program.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

bool global_app_running = false;

void my_exit()
{
global_app_running = false;
}

int main(int, char**)
{
global_app_running = true;
while(global_app_running)
{
// do stuff
if(AVARIABLE == ANOTHERVARIABLE)
my_exit();
}
return 0;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You should design your program to have one entry point and one exit point. This is usually in main. So, if we make a hypothetical game:


int main()
{
bool gameRunning = true;
do
{
processInput();
update();
render();
gameRunning = checkExitCondition();
}while(gameRunning);

return 0;
}


The program starts and ends in one place, main. Obviously this is an oversimplified case, but you can see how it makes the code easy to follow. Also, you don''t have to worry that there is another place that the program can abruptly end and you have a chance to close files, clean up memory etc. That is why you use levels of abstraction in your program design.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I didn''t say there was anything wrong with exit(), just don''t go nuts with it. There are times when you want to use it. I''m just saying look at your problem differently and you may find a better solution.

Share this post


Link to post
Share on other sites
I noticed that when I was reading it. I didn''t get far (decided I should keep reading up on C) but I think every exit can just be replaced with return.

Share this post


Link to post
Share on other sites
using exit is perfectly acceptable as long as you make sure to clean up any memory used by the program beforehand. I think what AP was sud. was that you make a global destructor of sorts, which is a good idea, but in not all cases plausable.

RICHARD

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok, Paul, why is what I said "sud"? I did not say "never ever ever use exit, it is teh evul1!!1". I said there are times when you should use it but to reconsider your program design first. Most of the time you don''t need it at all.

Share this post


Link to post
Share on other sites

  • Advertisement