Thread: Debuging

  1. #1
    Banned
    Join Date
    Jun 2005
    Posts
    594

    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.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    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.

  3. #3
    Banned
    Join Date
    Jun 2005
    Posts
    594
    ok thanks

    do i define the whole function to do the checking
    within the #define section?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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.

  5. #5
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    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

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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).

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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.

  8. #8
    Banned
    Join Date
    Jun 2005
    Posts
    594
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. debuging problem
    By dinamit875 in forum C++ Programming
    Replies: 21
    Last Post: 05-06-2009, 04:22 PM
  2. debuging help with opengl coding
    By efret in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2007, 02:23 PM
  3. debuging solution - crazy idea
    By ElastoManiac in forum Networking/Device Communication
    Replies: 1
    Last Post: 11-28-2005, 01:22 PM