3 ms·
Consider this (quite common) code: char buffer[LARGE_SIZE]; if(maybe_fill_buffer(buffer, sizeof(buffer))) { use_result(buffer); } The function may
by zrm 7d ago
Consider this (quite common) code:
char buffer[LARGE_SIZE];
if(maybe_fill_buffer(buffer, sizeof(buffer))) {
use_result(buffer);
}
The function maybe_fill_buffer() is an external library function that either fills the buffer and returns true or doesn't access it and returns false. Or maybe it unconditionally fills it, or unconditionally returns false without reading from it. The compiler can't see any of that though because it's in an external library. For all it knows that function is going to read from it instead of writing to it.
Notice that if it could actually figure it out 99% of the time then it could also emit a warning the 1% of the time that it can't and encourage you to make an explicit choice, which would have been a better option if that was actually the rate.