Summary
Jason Turner shares a subtle bug he encountered related to short-circuiting with the logical OR operator. He describes how in his ARM emulator, he used a pattern 'did_work = did_work || try_doing_work()' that caused the try_doing_work() function to execute at most once in a loop. This happened because once did_work became true, the short-circuiting behavior of the OR operator prevented the second operand from ever being evaluated again. Jason discusses several alternatives to fix this issue and recommends making short-circuiting logic clear through comments or better code structure when used in non-obvious ways.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[debugging]56% match