Change local variable references to be global variables.
Determine whether stack corruption is causing the problem.
Which stack variables were having their values overwritten?
Was the stack frame itself being overwritten?
This approach won’t work with algorithms that really need a stack.
Put preprocessor conditional compile directives around all stack variable declarations so you can switch between locals and globals.
Change local variable references to be heap variables pointed to by global variables.
Change heap variables to be located on the stack with the use of alloca (nonportable).
Put arrays of pad values between each true variable on the stack.
Use the basic or refined tactic when both of the following are true:
Symptoms change radically between runs.
Local variables are being overwritten, but their address isn’t being taken.
C++: This tactic can be useful for C++.
Java: Java guarantees heap integrity, so this tactic is unnecessary.
C: This tactic can be useful for C.
Fortran: This tactic is awkward to implement in Fortran.