Zitat von "Sven Neumann" <s...@gimp.org>:

> Hi,
> On Thu, 2010-04-22 at 14:38 +0200, Fredrik Alströmer wrote:
>> For the record, I'm not necessarily against setting a predefined value
>> to variables sometimes. I'm just against doing it for the wrong
>> reasons, and I'd much rather have the compiler say "Warning: might be
>> used uninitialized in this context" as a part of the static analysis,
>> rather than chase down the bug where a value is 0 at run time
>> (remember, I'm primarily talking corner cases here).
> Totally agreed. I also prefer the compiler telling me that a refactoring
> I've just done is not correct because I forgot to initialize a variable
> in a code path. This has happened to me and the compiler warning caught
> some potential bugs. If we would always initialize all variables this
> mistake would have gone unnoticed.

If this case would be undetected by the compiler, but you have  
initialized it to your EXCEPTIONAL value at the same line, at which  
the variable is defined,
then - when running the code, it would have shown you your problem.

Will the compiler stop execution on any warning? It should, and not  
compile any code that gives warnings, otherwise your attempt will not  
work. People will ignore it "just for testing". And that's the  
beginning of the problems ;-)

The other case is: values change during the meantime.
If you reset them to the exceptional values after usage,
especially I mean pointers here, that's a good idea.
And in those cases the compiler would not show you a warning
on non-initialized values, but the tests on validity will work.

BTW: just some days ago I saw a bug fix in glib.
In this fix, after freeing some memory, the pointer was set to null.
I was happy to see this. :)


Gimp-developer mailing list

Reply via email to