This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

On debug method(How to implement the "TRACE" macro?)

Dear all,my footprint of 51 on my project board is PLCC44,so the ICE can't be used(footprint is DIP40).I have to connect the 51's serial port to PC and dump everthing I need to it.So the program of debug version are full of "printf" statements which are unnecessary on release version.Thus,Can we write a "TRACE" macro to resolve it?MFC implement it for us while Keil C don't.

Parents
  • You need something like this:

    ifdef DEBUG
    //Debug mode - TRACE causes printf output
    #include <stdio.h>
    #define TRACE(params) printf params;
    #else
    //Release mode - TRACE expands to nothing!
    #define TRACE(params)
    #endif // DEBUG
    and use it like this:
    void some_func( char x )
    {
       TRACE( ("Entered some_func( %bX )", x) )
       :
       :
    }
    Note the use of two sets of parentheses - the outer set is part of the macro "call", and the inner set is taken as part of the parameter passed to the macro - and hence appears in (or disappears with) the macro expansion.

Reply
  • You need something like this:

    ifdef DEBUG
    //Debug mode - TRACE causes printf output
    #include <stdio.h>
    #define TRACE(params) printf params;
    #else
    //Release mode - TRACE expands to nothing!
    #define TRACE(params)
    #endif // DEBUG
    and use it like this:
    void some_func( char x )
    {
       TRACE( ("Entered some_func( %bX )", x) )
       :
       :
    }
    Note the use of two sets of parentheses - the outer set is part of the macro "call", and the inner set is taken as part of the parameter passed to the macro - and hence appears in (or disappears with) the macro expansion.

Children
No data