-
Debuging
i heard that you can have some kind of code, that let you
implement some debuging code that when a release is compiled
the debug code that you wrote wont be in the binary, and
you dont have to remove the code you just simply
set it on/off. if anyone know how to do this an example
would be wonderful, a site about how to do it would be great
to. hope taht was clear enough thanks for any responses.
-
Code:
#ifdef DEBUG_ME
void debugf(const char *format, ...);
#else
#define debugf (void)
#endif
Rough idea. when you wan to debug compile with DEBUG_ME defined, when you don't want to, don't.
-
ok thanks
do i define the whole function to do the checking
within the #define section?
-
Some IDE's will automatically create Debug and Release configurations where the debug configuration defines specific flags (for VC++ it's _DEBUG for debug and NDEBUG for release). Also, if your IDE provides the ASSERT macro, then anything insde the ASSERT will not be run in release mode but in debug mode it will and if it evaluates to false a message will pop up in your program indicating the failed ASSERT.
-
I have a related question, since debug and release are standard in MSVC++ but I dont define DEBUG or NDEGBUG anywhere...how does it know when I compile what i selected for my solution configuration?...is it in the solution configuration itself?..just curiouse :)
-
It is in the project properties (the .dsp or .vcproj files). When you create a new project, by default it creates two configurations - Debug and Release. One of the default settings is to add those preprocessor definitions (look under C/C++ Preprocessor in the project settings/properties).
-
ILoveVectors,
Your IDE (Visual Studio) has a debugger. I haven't really used it, but I have a general idea of how it works:
Regular machine code (.EXE file) doesn't contain line numbers, variable names, function names, or any of that stuff.
When you compile in the debug mode, the special EXE does contain that information (or pointers to that information... or somethin' ).
This allows you to monitor the program at the source code level while the compiled machine code is running.
With the debug version of the EXE and the debugger both running, you can watch variables change as the program runs, or stop execution at a breakpoint (a particular line number) and check variable values, etc. If your program crashes in debug mode, the debugger can tell you where it was, and what it was doing when it crashed.
-
actually that not quite what i want to know,
here is a example of what i need to know
Code:
#include <iostream>
#include <fstream>
using namespace std;
/* some code here that will be included when i compile
in debug mode, but will nto add any bloat or functionality
when i compile in release mode */
int main()
{
for(int num = 0; num != 100; num++)
{
//in here num will be manipulated mutiple times
//during each stage i want what num is equalled
//at each stage output to a file so i can make sure
//everything is going as accorrding. but i dont
//want this funcitonality in the final release
//when i do this with a regular output file i have
//extra 30 lines of code that i dont want to delete
//and add between all the testing.
}
return 0;
}
is that more clear, i think the one post above has the right idea
but they didnt elaberate enough for me to understand how to
use it because i have never used those preprocessor commands
or whatever they are before. thanks in advance