tags:

views:

131

answers:

2

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

+4  A: 

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.

Konrad Rudolph
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
Brian R. Bondy
A: 

Statics are always initialized to the default value (which for an int is 0). But you don't want them, do you?

dirkgently