3 ms·
Look at it as the compiler unrolling the loop to: if (table[0] == v) return true; if (table[1] == v) return true; if (table[2] == v) return true;
by ben0x539 12y ago
Look at it as the compiler unrolling the loop to:
if (table[0] == v) return true;
if (table[1] == v) return true;
if (table[2] == v) return true;
if (table[3] == v) return true;
undefined_behavior();
return false;
Since the compiler is allowed to assume undefined behavior never happens, and you certainly can't expect control to pass through undefined behavior and then do something reasonable like execute the next statement, the compiler can just assume that control exits the function before it gets to the undefined behavior, and the only way to do that is to take one of these `return true;` statements. It can't tell you which table element supposedly contains v, but no one asked for that, so all these `return`s serve equally well.
- codyb 12y agoBeautiful. That makes it very simple to understand. Cheers mate.