Using debug macro definition to turn on/off debug output in C/C++[Copy link]
debug macro as debug switch When writing a program, in order to debug, you often need to add some output statements, and then comment them out after debugging is completed. If you need to debug next time, you have to uncomment them, which is very time-consuming and laborious. In order to solve this trouble, you can define a debug macro as a debug output switch. As shown in the following code: #include
int main(void)
{
int i, sum;
for (i = 1, sum = 0; i <= 5; i++)
{
sum += i;
#ifdef DEBUG
printf("sum += %d is %d\n", i, sum);
#endif
}
printf("total sum is %d\n", sum);
}