如何在c中创建#define DEBUG

时间:2016-04-03 11:51:15

标签: c debugging

我只想在调试程序时调用printHex()。如果我将DEGUG设置为1将在下面的代码中调用printHex()?如果我将它设置为0将不会被调用?

#define DEBUG 1


TI_PUTS("Attempting to retrieve data\r\n")
sendCommand(Cmddata, Buffrec, sizeof(Cmddata)); //send a retrieve data command
clk_sys_delay(TWOSECOND); //delay 1 sec

#ifdef DEBUG
printHex("Data received\r\n", recBuff, sizeof(recBuff)); //print out received hex data
#endif

1 个答案:

答案 0 :(得分:0)

调试时使用#define DEBUG并使用// #define DEBUG,而不是......

或者您可以检查DEBUG == 1,例如

#if defined(DEBUG) && (DEBUG == 1)
 printHex("Data received\r\n", recBuff, sizeof(recBuff)); //print out received hex data
#endif

希望它有所帮助...