On 04/22/2010 03:54 AM, Marc Lehmann wrote:
> On Wed, Apr 21, 2010 at 08:14:33PM +0200, Martin Nordholts<ense...@gmail.com>
>> The compiler doesn't catch all cases, like this one:
>> int main(int argc, char **argv)
>> int var;
>> if (argc == 2)
>> var = 42;
>> printf ("var = %d", var);
>> return 0;
> 1. initialising var will not fix the bug, if there is any.
It won't, but it will make the bug consistently occur, which is a big plus.
> 2. initialising var will prevent other static analysers
> to diagnose a possible problem.
The problem to diagnose would be that of using an initialized variable,
no? The fix would then be to initialize the variable.
> 3. initialising var will prevent "weird effects"
> and just *might* decrease chances of finding the bug further.
Why would you want "weird effects" in software? That's exactly what you
don't want. At worst, a bug should manifest itself by making a program
not do what it was intended to do, not doing something unpredictable.
>> Since use of uninitlized variables very well can cause severe and
>> hard-to-reproduce crashes, and since unpredictability never is a good
> Actually, it's easy to diagnose those bugs though, just look at the
The coredump gives you the state of the program when it crashed, not the
cause leading up to the crash, which could have been an uninitlized
local variable that's no longer in any stack frame.
> Yes, don't do it unnecessarily, it tends to hide bugs.
Rather "As a rule of thumb, initialize local variables.". As always
there are cases where it's better not to initialize local variables.
Gimp-developer mailing list