gpt4 book ai didi

ios - 使用 ifndef 和 || 进行条件编译没有捕获第二种情况

转载 作者:可可西里 更新时间:2023-11-01 03:06:56 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com