当设置了两个定义中的一个或两个时,我试图禁用自动崩溃日志报告:DEBUG
用于我们的调试构建,INTERNATIONAL
用于国际构建。但是,当我尝试在 #ifndef
情况下这样做时,我收到警告 Extra tokens at end of#ifndef directive
and running with 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
之前是有效的。我也尝试过不使用 defined(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
关于ios - 使用 ifndef 和 || 进行条件编译没有捕获第二种情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535706/