Tag: 预处理程序指令

为什么我的简单C宏不起作用?

我想制作一个像这样调用printf()两次的简单宏 #ifdef ENABLE_DEBUGPRINTF #define DEBUGPRINTF(msg) printf(“At sim_time = %f:”, sim_time); printf(msg); #else #define DEBUGPRINTF(msg) //evalutes to nothing #endif 现在我打电话的时候 DEBUGPRINTF(“Processed event type: %d with value %f\n”, id, data) 它正确打印第一部分“at sime_time = …”但后面的部分显示“已处理事件…”,错误地打印了id和数据的值。 与此同时 printf(“Processed event type: %d with value %f\n”, id, data); 正确打印值。 当我尝试通过写出我认为宏将评估的内容来执行它时,我有。 printf(“At sim_time = %f:”, sim_time); printf(“Processed event type: %d with value […]