3 ms·
Maybe I'm just slow, but what was the bug in that code?
by troels 14y ago
Maybe I'm just slow, but what was the bug in that code?
- darklajid 14y agoHe explains it right in the text. if (someBool) return A; ... if (!someBool) return B; Now - both cases are covered. The result will be A or B, never anything else. Statements after the second return are unreachable.
- jgeralnik 14y agoAlmost. The result could be something else if it's in the code in the middle. It just won't ever get to whatever's after that return B.
- troels 14y agoAh .. He expected it to reach the unreachable code? I thought that it did reach `return R`, which would be totally strange and could indeed be explained by a compiler bug. (Or more likely, by side effects in the code between the two checks)