# #define Debug mode

This topic is 4853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In school they say that you should use a sort of Debug mode tag to generate errors so that the program pretty much crashes if there's an error so you know theres a problem, and when you release the game to take the Debug mode option out so if the program crashes, it crashes gracefully. So something like this if (DEBUG) { CrashHard(); }else { CrashGracefully(); } That way when you release the game to the public you can just not define DEBUG and the program won't crash as hard. My question is, is this a good idea for game programming, since that makes that many more if statements it has to evaluate? I know it won't totally slow the game down or anything, but evey little bit helps. Sorry If I wasn't totally clear on this. I'm tired right now.

##### Share on other sites
Rather than doing:

if (DEBUG){CrashHard();}else{CrashGracefully();}

you should do:

#ifdef DEBUGCrashHard();#elseCrashGracefully();#endif

That way it's all handled by the preprocessor before compilation, so your actual program will not be affected by any extra if statements.

##### Share on other sites

#ifdef DEBUG#define DEBUG_ONLY(x) x#else#define DEBUG_ONLY(x) 0#endif

Now, if your project is DEBUG, you could compile it with -DDEBUG in gcc, or your compiler equivalent. Or you could just #define DEBUG in your program somewhere. So later in your code, when you have

DEBUG_ONLY(CrashHard());CrashGracefully();

Assuming crash hard will exit your program, CrashGracefully() will never be called. But if you dont define DEBUG, CrashHard will not occur.

If your functions return 1 or something, you could do something like

if(!DEBUG_ONLY(SomeFunc()){   SomeOtherFunc();}

Roight!

##### Share on other sites
ahhhh, i see. Thanks.

##### Share on other sites
You probably also want use the macro NDEBUG (not in debug mode), since it's standard and will thus be automatically defined by your compiler.
Oh, and assert() can be a good tool too.