Silverfrost Logo About Us | Contact Us

Array subscript checking

The /CHECK option ensures that every array reference lies within the storage allocated to the array. Each individual subscript expression is also checked. Consider the following coding:

I = 11
J = 7
A(I,J) = 0.0

The storage element referenced by the subscripts lies within the declared storage for the array even though the first subscript is outside its corresponding bound. This is not valid Fortran 95 (although it is valid Fortran 66).

Using the above DIMENSION statement for A, it is apparent that the statement

I = 11
J = 10
A(I,J) = 0.0

would cause a run-time error if either of the compiler options were used.

In general, array bound checking incurs a run-time overhead of both store and execution speed. Full array bound checking for multi-dimensional arrays is very costly. The simpler array bound check is less so.

Array bound checking is available for arrays of any type. The array may have explicit dimensions, for example:


or may be passed as arguments with variable bounds, for example:


The checks will work in all cases for both upper and lower bounds.

Note: When using Fortran 90 assumed-shape arrays in an external subprogram, you must provide a corresponding INTERFACE statement where the subprogram is called.

If checking is not in use, unpredictable effects may occur at run-time. An attempt to transfer a value from an element outside the bounds of an array can either:

  1. assign or use an arbitrary value which might cause overflow, or

  2. cause the program to fail with general protection fault which means that the program has tried to access storage outside the limits available to it, or

  3. overwrite a pointer and cause a fault in a different part of the program.

If an attempt is made to transfer data to an element outside the defined bounds of an array without specifying the checks, the effects are to tally unpredictable and will frequently result in a spurious error when some unrelated part of the program is executed.



Copyright © 1999-2017 Silverfrost Limited