User: Password:
Subscribe / Log in / New account

Removing uninitialized_var()

Removing uninitialized_var()

Posted Dec 20, 2012 14:18 UTC (Thu) by clugstj (subscriber, #4020)
In reply to: Removing uninitialized_var() by nevets
Parent article: Removing uninitialized_var()

NULL is better than "anything else". The reason to set a variable to a consistent invalid value is that then the code fails consistently. Consistent bugs are much easier to track down.

(Log in to post comments)

Removing uninitialized_var()

Posted Dec 21, 2012 5:29 UTC (Fri) by nevets (subscriber, #11875) [Link]

No, NULL may be better than uninitialized_var(), but it is not better than hiding gcc from warning about it.

Yes, a NULL pointer is easy to debug after a crash, but if it requires a tight race to get to a point where NULL will crash, that means you wont detect the bug until the crash happens. If that crash happens while on a production system, it's still a major issue.

My point is that uninitialized_var() isn't very good because it may hide bugs, but so is blindly initializing something, even with NULL. It's still hiding a bug.

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds