[置頂]

書單: 安迪葛洛夫:Only paranoid survives.

Nov 4, 2014

[from K&R] && execution order

Expressions connected by &&
or || are evaluated left to right, and it is guaranteed that evaluation will stop as soon as the truth or falsehood is known. If c is
a blank, there is no need to test whether it is a newline or tab, so these tests are not made. This isn’t particularly important
here, but is significant in more complicated situations, as we will soon see.


http://stackoverflow.com/questions/2456086/if-with-multiple-conditions-order-of-execution
From draft 3485 (n3485.pdf) Its clearly stated that

5.14 Logical AND operator [expr.log.and]

logical-and-expression: 
      inclusive-or-expression
      logical-and-expression && inclusive-or-expression 
  1. The && operator groups left-to-right. The operands are both contextually converted to bool (Clause 4). The result is true if both operands are true and false otherwise. Unlike &, && guarantees left-to-right evaluation: the second operand is not evaluated if the first operand is false.

No comments: