[cfe-dev] new -Wuninitialized implementation in Clang

Michael Price - Dev michael.b.price.dev at gmail.com
Fri Feb 4 06:02:22 PST 2011


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);

> John
> _______________________________________________
> 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