Use compiler options to initialize statically with unusual or invalid values those global variables that aren’t explicitly initialized.
Identify uninitialized variables that need to be initialized.
Which global variables are getting random values that are being used in computation?
Where is the first place that the random values are being used?
Computations may not fail with the values assigned.
Initialize floating-point variables to IEEE Not a Number (NaN), pointer variables to an invalid address, and integer variables to the maximum representable integer.
Add code that initializes all global variables.
Run on a different system, where 0 isn’t a valid address.
Use the refined tactic when your compiler doesn’t support an option for the basic tactic.
Use basic or related tactics when any of the following is true:
A bug occurs when the program is run standalone, but not when it’s run under a debugger.
A bug occurs when the program is run under one user account (and environment), but not when it’s run under another.
Use this tactic at least once before the program is put into production, as an additional testing strategy.
C++: Use constructors to ensure that all class members are properly initialized.
Java: Java doesn’t have global variables. Class members are always initialized, so the tactic is unnecessary.
C: Some C implementations initialize all global variables to 0, while others do not. If you aren’t using a compiler that conforms to the C99 standard, don’t rely on this behavior.
Fortran: Some Fortran implementations initialize all numeric variables in COMMON to 0. You shouldn’t rely on this behavior if you aren’t using a compiler that guarantees this behavior.