0
我想在某些预处理器宏中编写代码来选择性地记录某些信息。例如在.M的.H用于可选日志记录的预处理器调试宏
//#define ML_DEBUG(x) (x) // flip this bit to do the error logging
#define ML_DEBUG(x) (1==1) // flip this bit to silence
我实现诸如:
ML_DEBUG(NSLog(@"Class dealloc: %@", [NSString stringWithCString:object_getClassName(self)]));
,因为我已经提出了它的代码工作正常。不过,我认为我的“无所事事”案件的重量轻得可怕。我早就预料到写:
//#define ML_DEBUG(x) (x) // flip this bit to do the error logging
#define ML_DEBUG(x) (;) // flip this bit to silence
因为一个孤独分号是一个有效的Objective-C的说法,我希望这会工作,但编译器告诉我:
expected expression before ';' token
我的问题是:我通过使用1==1
来选择最轻量级的“无所事事”声明,或者有没有一种不太密集的方式来做到这一点。或者,也许我的整个临时调试日志记录的方法是错误的?