Friday, April 8, 2011

Forcing ints to initialize to 0 msvc++

Is there any compiler setting or other way to force an int to be initialized to 0?

From stackoverflow
  • Is there any compiler setting or other way to force an int to be initialized to 0?

    Unfortunately, there is no way in the language and if the compiler offers such a setting it goes against the standard and therefore should not be used.

    May I ask why you need this? Is explicit initialization not enough? Or would you like to be warned when uninitialized memory i used? The latter can be achieved using valgrind's memory profiler.

    Brian R. Bondy : Basically just for a catch all in case there were any bugs caused by uninitialized values. the memory profiler sounds like what I need, thanks
  • Statics are always initialized to the default value (which for an int is 0). But you don't want them, do you?

0 comments:

Post a Comment