短路评估是 C/C++ 或编译器实现中的语言功能

Is short circuit evaluation a language feature in C/C++ or compiler implementation

我想知道是否短路评估

long param = 0;
if ( functAWithSideEffects(&param) || funcBWithSideEffects(&param) )

可以依靠。例如,如果 funcAWithSideEffects returns 为真,编译器会评估 funcBWithSideEffects 吗?短路评估是语言特性还是编译器实现细节?

是的。值得信赖。

C standard 保证它(强调我的):

4 Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; if the second operand is evaluated, there is a sequence point between the evaluations of the first and second operands. If the first operand compares unequal to 0, the second operand is not evaluated.

虽然 C++ 在几个方面与 C 不同,但我 99.99% 确定短路评估不是其中之一。

可以为 && 找到类似的保证。