Skip to main content
gamedev.net
🔒 Locked

simple question about debugging...

Started by jasonf Jun 18, 2002 at 7:11 PM 4 replies 450+ views
Original Post
jasonf
jasonf
Geez, now the fact that i went to school 10 years ago is really starting to show Here''s my question. I have a bunch of debug text that is outputed from my app. is there a way that i can define a state as say COMPILEWITHDEBUGTEXT so that when i compile, i can make it either true or false. then if compiled with the state as false, it wouldn''t even bother compiling the lines that are stated as debug text. would this be an assert??? this type of info tends to slip out over the years if not used help!
Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com
jasonf
jasonf
oops...i''m using msvc++.

Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com
Martee
Martee
Sounds like you want to take advantage of the preprocessor. You can use something like this:

#ifdef COMPILEWITHDEBUGTEXT
output_lots_of_useful_debug_info();
#endif

Then you just have to add COMPILEWITHDEBUGTEXT to the list of preprocessor defines for debug mode, or just add #define COMPILEWITHDEBUGTEXT somewhere. Oh, and IIRC, MSVC gives you _DEBUG_ (in debug mode) and NDEBUG (in release mode) by default.

[edited by - Martee on June 18, 2002 8:20:48 PM]
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Beren77
Beren77
you can implement debug information "on demand" by using a #define statement (I think, in this case, it is not a hack, but actually useful). Something like:

#ifdef __DEBUG
void PrintDebugText(char *message, ...)
{
// write information to a file (or to the screen)
}
#else
#define PrintDebugText //
#endif

So: If you define __DEBUG before compiling, you have a function PrintDebugText that puts your message to screen or to disk. If you do not define it, PrintDebugText-Statements are interpreted as "//(char *message, ...);" (example: //("Called constructor.");"
Just be careful, however, that you do not add another statement in the same line as the PrintDebugText-statement, which would be commented otherwise.

Beren
IndirectX
IndirectX
MSVC by default already defines _DEBUG for you when you''re building your debug builds, so you should use that.

#ifdef _DEBUG
CallDebugOnlyFunction();
#endif

#ifndef _DEBUG
CallReleaseOnlyFunction();
#endif
---visit #directxdev on afternet <- not just for directx, despite the name
jasonf
jasonf
ah yes, it all starts to come back to me.

thanks for the help lads.

jason.
Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.