3 ms·
I feel like I'm missing something. Even if we assume i is never 4 or 5, why can we assume that v is contained in the table? Even with undefined behavior, it see
by wtetzner 7y ago
I feel like I'm missing something. Even if we assume i is never 4 or 5, why can we assume that v is contained in the table? Even with undefined behavior, it seems like that's bugger compiler behavior.
By the author's logic, even if the undefined behavior didn't exist, you can still assume i is never 4 or 5, but that doesn't meant the function always returns true. Is there something I'm not understanding here?
- Arnavion 7y agoOnce the i == 4 and i > 4 cases have been eliminated, all code paths in the function return true. It's helpful to remember that the if (table[i] == v) return true; line has an implicit `else continue;` clause, not an `else return false;` clause.
- wtetzner 7y agoOk, so because i never reaches 4, it assumes the loop doesn't exit due to the 'for' condtion, so it must return true. That makes sense, but still feels like a broken way to do optimizations.