Monday, 15 September 2014

Why don't C++ compilers zero-initialize integer, floating-point, and pointer variables by default? -



Why don't C++ compilers zero-initialize integer, floating-point, and pointer variables by default? -

sometimes, can utilize tools valgrind find out if forgot initialize pointer variable. why don't modern compilers relieve mutual error hard reproduce?

initialization not desirable:

for performance reasons; initializing memory takes time may not necessary. there algorithms depend on constant time allocation accomplish desired performance (initialization linear time). d recognizes has different (probably better) approach; variables initialized default has special syntax prevent initialization.

sometimes there no right default value. static analysis or runtime debugging features can help observe when variable used without initialization. assigning (incorrect) value them default hide bug detected using these.

c++

No comments:

Post a Comment