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.
MFC implement it for us while Keil C don't I'll get back to you when I'm done with my port of MFC to the 8051. I still have some issues with the DirectX 9 support for multiprocessor support. In the meantime, it's a pretty easy macro to write: #if DEBUG #define TRACE(args) printf(args) #else #define TRACE(args) #endif Define DEBUG, and you get your debug code. Don't define it, and the statements all vanish. If I've got a fancy CLI to play with, I like to add a "debug level" to the macro to control verbosity of the output. I assign the debug output to "high", "medium", "low" levels of detail (1, 2, 3). Then, I can use an 'if' statement to compare to a dynamically controlled debug level variable so that I'm not always buried in the maximum spew from the debug code, but can turn it on when I want. A little more macro sleight-of-hand lets you selectively compile out debug levels you don't want in the code. Different preprocessors seem to handle the problem of variable arguments differently. That is, if you have printf ("%d %d %d\n", d1, d2, d2); you may or may not be able to call TRACE ("%d %d %d\n", d1, d2, d2); since there are four actual arguments to TRACE but only one formal argument declared. Some preprocessors simply make the last argument match all arguments to the macro. If I recall correctly, C99 actually adds support for variadic macro declarations. But I also can sometimes get away with an extra level of parens: TRACE (("%d %d %d\n", d1, d2, d2)); which is a little ugly, but groups all the arguments into one single one for the macro expansion.
The extra level of parenthesis works fine with C51.
View all questions in Keil forum