difference between quit and exit
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
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 ]
[ 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 ]
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
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
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;}
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
retrospiral.net | llamas! | megatokyo | gamedev.net | google
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:
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.
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 ]
[ 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 ]
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
retrospiral.net | llamas! | megatokyo | gamedev.net | google
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement