【发布时间】:2023-03-15 04:23:01
【问题描述】:
我只想在定义_DEBUG 时打印信息
#define DEBUG(y) y == true ? #define _DEBUG true : #define _DEBUG false
#ifdef _DEBUG
#define Print(s) printf(s);
#endif
出现错误:
error: '#' is not followed by a macro parameter
任何建议如何使用预处理器指令来实现这一点?
我打算将它从我的主要用作:
DEBUG(true);
Print("Inside main in debug mode");
【问题讨论】:
-
据我了解,预处理器语句是在编译之前进行评估的。因此,预处理将在应用您的任何逻辑之前评估 #Define 语句。 @JohnZwinck 采用与我相同的方法。