预处理中的多个定义条件
Multiple defined conditions in preprocessing
我知道我可以制定一些复杂的条件,例如:
#if defined(A) || defined(B) || defined(C)
但是,如果我想要这样的条件:
A || (B && C)
我可以使用括号吗,否则预处理器会忽略它并强制我编写一些嵌套条件?
我试过:
#if defined(A) || (defined(B) && defined(C))
而且有效。但只是为了确保它不 platform/compiler 依赖或其他任何东西,因为我找不到任何这样的例子。
谢谢
是的,它应该可以工作,因为预处理器将首先检查括号。
在 C99 标准中
6.10 Preprocessing directives
if-group:
#if constant-expression new-line groupopt
6.6.3
Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated
defined(A) || (defined(B) && defined(C))
当然是一个有效的常量表达式,所以它必须工作
我知道我可以制定一些复杂的条件,例如:
#if defined(A) || defined(B) || defined(C)
但是,如果我想要这样的条件:
A || (B && C)
我可以使用括号吗,否则预处理器会忽略它并强制我编写一些嵌套条件?
我试过:
#if defined(A) || (defined(B) && defined(C))
而且有效。但只是为了确保它不 platform/compiler 依赖或其他任何东西,因为我找不到任何这样的例子。
谢谢
是的,它应该可以工作,因为预处理器将首先检查括号。
在 C99 标准中
6.10 Preprocessing directives
if-group:
#if constant-expression new-line groupopt
6.6.3
Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated
defined(A) || (defined(B) && defined(C))
当然是一个有效的常量表达式,所以它必须工作