Buried in warnings
Buried in warnings
Posted Nov 2, 2006 5:20 UTC (Thu) by JoeBuck (subscriber, #2330)Parent article: Buried in warnings
A typical example of a false uninitialized variable warning gcc will generate is the following:
bool flag = false;
some_type* pointer;
if (some_condition_is_true()) {
flag = true;
pointer = expensive_allocation_function();
}
do_something_else();
if (flag) {
use_the_fine(pointer);
}
GCC will report that pointer might be used uninitialized, because it does not track the association between the flag variable and the state of pointer. Doing checks of this kind would require rather sophisticated analysis; gated static single assignment would work, but even then, there are cases that a human being can immediately see that the compiler will not. However, use of an uninitialized object can be such a disaster that most consider false positives better than false negatives.
Sometimes suppressing the warning will require a minor time and space penalty: say, an instruction to set some object to zero. Unless you're dealing with the most time-critical of inner loops, I suggest that you're better off trying for a clean compilation with -Wall, even if there is a minor cost, because a microscopically faster but more buggy program isn't worth the cost.
