我正在尝试在设置两个定义中的一个或两个时禁用自动崩溃日志报告:DEBUG用于我们的调试版本,INTERNATIONAL用于国际版本.但是,当我尝试在#ifndef情况下执行此操作时,我会在#ifndef指令结束时收到警告Extra标记,并且运行DEBUG定义将触发Crittercism.
#ifndef defined(INTERNATIONAL) || defined(DEBUG) // WE NEED TO REGISTER WITH THE CRITTERCISM APP ID ON THE CRITTERCISM WEB PORTAL [Crittercism enableWithAppID:@"hahayoudidntthinkidleavetherealonedidyou"]; #else DDLogInfo(@"Crash log reporting is unavailable in the international build"); // Since Crittercism is disabled for international builds,go ahead and // registers our custom exception handler. It's not as good sadly NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); DDLogInfo(@"Registered exception handler"); #endif
这个真值表显示了我的期望:
INTL defined | DEBUG defined | Crittercism Enabled F | F | T F | T | F T | F | F T | T | F
这之前它只是#ifndef INTERNATIONAL.我也试过没有定义的(blah)和括号围绕整个语句(分别是相同的警告和错误).
如何从编译器中获得我想要的行为?
解决方法
你要:
#if !defined(INTERNATIONAL) && !defined(DEBUG) // neither defined - setup Crittercism #else // one or both defined #endif
或者你可以这样做:
#if defined(INTERNATIONAL) || defined(DEBUG) // one or both defined #else // neither defined - setup Crittercism #endif