Re: [問題] if ( a && b ) 一定會執行到b嗎?
short-circuit 是有規定的標準行為
C standard 6.5.13p4
Unlike the bitwise binary & operator, the && operator guarantees left-to-right
evaluation; there is a sequence point after the evaluation of the first operand.
If the first operand compares equal to 0, the second operand is not evaluated.
C++ standard 5.14
Unlike &, && guarantees left-to-right evaluation: the second operand is not
evaluated if the first operand is false.
所以如果你的寫法出現 bug
那有兩種可能
1. 你的 compiler 有 bug
2. 你的 code 其它地方有 bug
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.168.65.197
→
10/09 13:57, , 1F
10/09 13:57, 1F
推
10/09 15:02, , 2F
10/09 15:02, 2F
推
10/09 16:44, , 3F
10/09 16:44, 3F
推
10/09 20:40, , 4F
10/09 20:40, 4F
→
10/09 20:40, , 5F
10/09 20:40, 5F
→
10/09 22:09, , 6F
10/09 22:09, 6F
→
10/09 22:09, , 7F
10/09 22:09, 7F
→
10/09 23:07, , 8F
10/09 23:07, 8F
推
10/09 23:28, , 9F
10/09 23:28, 9F
→
10/09 23:29, , 10F
10/09 23:29, 10F
→
10/09 23:30, , 11F
10/09 23:30, 11F
推
10/09 23:43, , 12F
10/09 23:43, 12F
推
10/11 02:59, , 13F
10/11 02:59, 13F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 4 篇):