ios – 使用ifndef和||进行条件编译不会遇到第二种情况

我正在尝试在设置两个定义中的一个或两个时禁用自动崩溃日志报告: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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...