difference between quit and exit

Started by
14 comments, last by zer0wolf 20 years, 6 months ago
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
laziness is the foundation of efficiency | www.AdrianWalker.info | Adventures in Game Production | @zer0wolf - Twitter
Advertisement
There is no quit() command in either C or C++.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
And, you should probably not be using exit(). There are uses for it, but it is not an "elegant" way to terminate your program.
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
laziness is the foundation of efficiency | www.AdrianWalker.info | Adventures in Game Production | @zer0wolf - Twitter
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;}  

return 0 at the end of your main function.

Thank you muchos. I will give it a whirl

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | gamedev.net | google
laziness is the foundation of efficiency | www.AdrianWalker.info | Adventures in Game Production | @zer0wolf - Twitter
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.
There''s nothing wrong about multiple exit points : RAII.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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
laziness is the foundation of efficiency | www.AdrianWalker.info | Adventures in Game Production | @zer0wolf - Twitter

This topic is closed to new replies.

Advertisement