尝试使用如下条件编译时,出现以下错误: 注意:请注意,一个,两个和三个是预处理器定义的符号,而三个是宏,使用的编译器是IAR(IDE AtmelStudio)
#if (defined(ONE) && !defined(TWO)
#if (SUM)
&& !defined(THREE)
#endif
)
some_statements_1
#else
some_statements_2
#endif /* #if (defined(ONE) && !defined(TWO) */
我希望仅在定义some_statements_1
ONE
且未定义TWO
的情况下执行SUM
情况1:如果THREE
设置为> 0,则不应定义SUM
情况2:如果THREE
设置为0,则照常(不检查Pe018: expected a ")" at line 1 and
error: Pe169: expected a declaration at line 3
)
实际结果是:
D8: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\admin\AndroidStudioProjects\login_program\build\app\intermediates\transforms\dexBuilder\debug\2.jar, C:\Users\admin\AndroidStudioProjects\login_program\build\app\intermediates\transforms\dexBuilder\debug\3.jar, C:\Users\admin\AndroidStudioProjects\login_program\build\app\intermediates\transforms\dexBuilder\debug\4.jar, C:\Users\admin\AndroidStudioProjects\login_program\build\app\intermediates\transforms\dexBuilder\debug\5.jar, C:\Users\admin\AndroidStudioProjects\login_program\build\app\intermediates\transforms\dexBuilder\debug\6.jar, C:\Users\admin\AndroidStudioProjects\login_program\build\app\intermediates\transforms\dexBuilder\debug\7.jar,
答案 0 :(得分:2)
预处理器条件行上的表达必须是独立的。您不能将#if
放在预处理器表达式的中间。
尝试:
#if defined(ONE) && !defined(TWO) && !((SUM) && defined(THREE))
some_statements_1
#else
some_statements_2
#endif
我假设SUM
是一个宏,它扩展为适合预处理器评估的整数常量表达式。
(已编辑:是#if defined(ONE) && !defined(TWO) && (!(SUM) || defined(THREE))
答案 1 :(得分:-1)
if(defined(ONE)&&!defined(TWO)
在上面的语句中,您错过了一个右括号。请添加