当设置了两个定义中的一个或两个时,我尝试禁用自动崩溃日志报告:DEBUG
对于我们的调试版本和INTERNATIONAL
为国际建筑做准备。当我尝试在#ifndef
case,然而,我得到了警告Extra tokens at end of #ifndef directive
和运行DEBUG
定义将触发判断主义。
#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)
并用括号将整个语句括起来(分别是相同的警告和错误)。
如何从编译器获得我想要的行为?
发布于 2013-08-30 22:46:09
您需要:
#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
发布于 2021-02-26 14:03:24
我只找到一个帖子条件Compilation哪一个可以更好地解释#if
/#elif
和#ifdef
/#ifndef
从语法级别:
#if constant-expression newline
#ifdef identifier newline
#ifndef identifier newline
#else newline
#elif constant-expression newline
#endif newline
所以在这里我们可以看到#ifndef
后面必须跟'identifier',这通常是由定义的宏#define
指令,或者@rmaddy说“一个值”。但是if
后面可以跟“constant- expression”,这样条件表达式defined(INTERNATIONAL) || defined(DEBUG)
或者!defined(INTERNATIONAL) && !defined(DEBUG)
可以使用。
https://stackoverflow.com/questions/18535706
复制相似问题