Use compiler options to generate runtime subscript checking.
Determine whether there are any array subscripts that are invalid for the test data you have available.
Where are invalid array references coming from?
When are invalid array references occurring?
If your program makes a lot of array references in tightly nested loops, you could slow down execution significantly.
Some compilers don’t offer this option.
Put pad variables between arrays so that invalid references that haven’t been found yet don’t effect computation.
Reorder array declarations so that invalid references that haven’t been found yet don’t effect computation.
Use preprocessor macros to cover array accesses and check subscripts.
Use this tactic when one of the following conditions is true:
The compiler doesn’t do subscript checking by default.
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++: Pointer arithmetic can be the equivalent of array indexing, so it’s desirable to check pointer references as well.
Java: The Java runtime always checks array references, so the tactic is unnecessary.
C: Pointer arithmetic can be the equivalent of array indexing, so it’s desirable to check pointer references as well.
Fortran: This tactic isn’t relevant to Fortran pointers.