MISRA.LOGIC.SIDEEFF.CONDBranch expression in a conditional expression contains side effects. MISRA-C Rule 12.4 (required): The right-hand operand of a logical && or || operator shall not contain side effects.This rule is also covered by MISRA.LOGIC.SIDEEFF. There are some situations in C code where certain parts of expressions may not be evaluated. If these sub-expressions contain side effects then those side effects may or may not occur, depending on the values of other sub expressions. The operators which can lead to this problem are &&, || and ?:. In the case of the first two (logical operators) the evaluation of the right-hand operand is conditional on the value of the left-hand operand. In the case of the ?: operator, either the second or third operands are evaluated but not both. The conditional evaluation of the right-hand operand of one of the logical operators can easily cause problems if the programmer relies on a side effect occurring. The ?: operator is specifically provided to choose between two sub-expressions, and is therefore less likely to lead to mistakes. Exampleif ( ishigh && ( x == i++ ) ) /* Not compliant */ if ( ishigh && ( x == f(x) ) ) /* Only acceptable if f(x) is known to have no side effects */ The operations that cause side effects are described in section 5.1.2.3 of ISO/IEC 9899:1990 [2] as accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations, which cause changes in the state of the execution environment of the calling function. |