help with DUMP function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matt287
    New Member
    • Jul 2007
    • 3

    help with DUMP function

    Hi,

    I am tracing this c program and I know nothing about this x_DUMP code. Can somebody explain to me ? Thanks.
    [code=c]
    /* header */
    # include <stdlib.h>
    # if x _DUMP
    # include <stdio.h>
    # endif

    /* functions */

    void function_name (int something)
    {

    # if x_DUMP
    printf(" this is function a ");
    fflush(stdout);
    #endif

    printf("somethi ng");
    }

    # if x_DUMP
    void x_dump( )
    {

    printf("somethi ng");
    printf(" something");

    fflush(stdout);
    }

    # endif[/code]
    Last edited by sicarie; Jul 3 '07, 04:44 PM. Reason: Please use [code=c] and [/code] tags around your code.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The person who wrote this code did not know how to use a debugger. So instead, a bunch of printf() statements are spattered all over the application.

    Now when you build, if you define x_DUMP, all those printf() will be part of the build. Then when the program is working you build again without defining x_DUMP and all the printf() are not part of the build.

    The problem with this appraoch is that the program that tested with x_DUMP defined is not the same code with x_DUMP not defined. In effect, you release untested code.

    Personally, I would rip all if the x_DUMP out of the code and start using a debugger.

    Don't forget that you can also use asserts.

    Comment

    • matt287
      New Member
      • Jul 2007
      • 3

      #3
      Thank you so much for the explanation. Actually each of separated functions contain more than 500 lines of codes. Maybe it is easier for us to trace either is is functioning or not with the x_DUMP. The problem now is I don't know how to invoke the x-DUMP in each function. What should I do?

      Thank you.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You just need to define x_DUMP.


        x_DUMP does not need to be a particular value.

        #define x_DUMP

        is all you need.

        If there is a header file that is included in all of your course files you could put the #define in that header. It is preferable, though, to define x_DUMP on the command line of the compiler. That way, you don't have to remember to delete the #define and rebuild before releasing your code.

        If you use Visual Studio.NET, you can define this in the project properties under C/C++ and the PreProcessor.

        All this does is make the compiler command line contain -Dx_DUMP.

        If you are not using Visual Studio, check out how to set preprocessor directives as property values.

        Comment

        • matt287
          New Member
          • Jul 2007
          • 3

          #5
          Thank you so much. The x_DUMP already defined in the header file, x.h .

          When I checked the header file , x.h , one of the line of code already defined x_DUMP as follow:

          #define TTHEAP_DUMP 0

          Roughly, 2 files involved: x.c and x.h

          x.c call the x.h file.

          coding in the x.c are as mentioned above , and the x.c also had #include <x.h>

          In the x.h , it defined the x_DUMP , as #define TTHEAP_DUMP 0

          There is no main function in the x.c

          I don't know how to trace the program.

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Originally posted by matt287
            In the x.h , it defined the x_DUMP , as #define TTHEAP_DUMP 0
            This defines TTHEAP_DUMP and not x_DUMP.

            What, exactly, is the code in your x.h header?

            If there is no main() in x.c, then x.c is part of a larger program. If you want to debug the code in x.c, you set a debugger breakpoint and wait for the path of execution to go into x.c where it will hit your breakpoint, stop, and drop you into your debugger. Then yoyu can step through the code.

            Comment

            Working...