Removing uninitialized_var()
Removing uninitialized_var()
Posted Dec 20, 2012 2:47 UTC (Thu) by nevets (subscriber, #11875)Parent article: Removing uninitialized_var()
My experience was that, depending on which version of gcc you used, it may or may not complain about a possible uninitialized var. I had some code that gcc 4.6+ had no issue with, but 4.5.x did. I would constantly get a patch to initialize the variable (a pointer) to NULL. I refused each patch simply because 4.6 didn't complain, and more importantly, if the variable was used outside of the expected path, a NULL pointer would crash it. If I later changed the code where the variable was used without the proper initialization, the NULL was no better than anything else, and it would hide the bug just as much as uninitialized_var() would.
I'm a bit weary of default initialization. You need to look at the code to determine if what you initialized the variable to is any better than it being random.
