[cfe-dev] new -Wuninitialized implementation in Clang
jahanian
fjahanian at apple.com
Fri Feb 4 10:15:04 PST 2011
On Feb 4, 2011, at 6:02 AM, Michael Price - Dev wrote:
> On Feb 4, 2011, at 12:32 AM, "John N. Lehner" <jlehner at apple.com> wrote:
>
>> On Feb 3, 2011, at 8:27 PM, Johannes Schaub (litb) wrote:
>>
>>> Ted Kremenek wrote:
>
> <snip>
>
>>>
>>> Hmm, I would personally like to not initialize variables that I
>>> know are not
>>> read from, as in your above code example. I personally regard it as
>>> bad
>>> coding style to initialize variables with values not really used by
>>> the
>>> code.
>>
>> I follow this philosophy as well (but my coworkers think I'm
>> crazy). While blindly initializing all variables to, say, zero will
>> decrease the likelihood of nondeterministic runtime behavior, it
>> doesn't necessarily contribute to program correctness. What if the
>> above example was "fixed" to suppress a spurious warning, but is
>> then extended during maintenance:
>>
>> int x = 0;
>> ...
>> if (flag)
>> x = ...
>> ...
>> if (flag)
>> use(x);
>> ...
>> use(x);
>>
>> and use(0) is wrong. While that may seem contrived, I saw it happen
>> in a loop once, and use(0) turned out to be expensive.
>
> I strongly disagree. How can use(0); be worse than use(garbage that
> can potentially be zero or that can potentially crash your app causing
> data corruption);
It is worse because it masks a logical bug which which is masked out by this initialization.
Better to have an occasional crash than something which seems to 'work'.
- fariborz
>
>> John
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list