Archived

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

difference between quit and exit

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 on other sites
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 on other sites
Hmmm... the quit() command works only with VS then?

Whats the best way to exit if exit() isn''t the "most elegant" way of doing it?

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | gamedev.net | google

Share on other sites
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 on other sites
return 0 at the end of your main function.

Share on other sites
Thank you muchos. I will give it a whirl

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | gamedev.net | google

Share on other sites
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 on other sites
The main reason I''m asking because I''ve trying using the tuts on the libsdl page and the VS compiler is bitching at me about the exit() command in it.

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | gamedev.net | google

Share on other sites
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 on other sites
I don''t remember the exact error, but the damned compiler doesn''t even recognize the command for some reason....

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | gamedev.net | google

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 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 on other sites
What Aerolithe said worked, I just had to replace all of the damned exit()''s with returns. Works peachy now

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | gamedev.net | google

Share on other sites
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.

• Forum Statistics

• Total Topics
628329
• Total Posts
2982104

• 22
• 9
• 9
• 13
• 11