| Cray Fortran CompilerTM Commands and Directives Reference Manual - S-3901-51 | ||
|---|---|---|
| Prev Section | Chapter 4. Cray Fortran Compiler Directives | Next Section |
Certain directives provide local control over specific compiler features. They are as follows:
BOUNDS and NOBOUNDS
FREE and FIXED
The -f and -R command line options apply to an entire compilation, but these directives override any command line specifications for source form or bounds checking. The following subsections describe these directives.
Array bounds checking provides a check of most array references at both compile time and run time to ensure that each subscript is within the array's declared size.
Note: Bounds checking behavior differs with the optimization level. Complete checking is guaranteed only when optimization is turned off by specifying -O 0 on the ftn command line.
The -R command line option controls bounds checking for a whole compilation. The BOUNDS and NOBOUNDS directives toggle the feature on and off within a program unit. Either directive can specify particular arrays or can apply to all arrays. The formats of these directives are as follows:
|
| array | The name of an array. The name cannot be a subobject of a derived type. When no array name is specified, the directive applies to all arrays. |
BOUNDS remains in effect for a given array until the appearance of a NOBOUNDS directive that applies to that array, or until the end of the program unit. Bounds checking can be enabled and disabled many times in a single program unit.
Note: To be effective, these directives must follow the declarations for all affected arrays. It is suggested that they be placed at the end of a program unit's specification statements unless they are meant to control particular ranges of code.
The bounds checking feature detects any reference to an array element whose subscript exceeds the array's declared size. For example:
REAL A(10)
C DETECTED AT COMPILE TIME:
A(11) = X
C DETECTED AT RUN TIME IF IFUN(M) EXCEEDS 10:
A(IFUN(M)) = W |
The compiler generates an error message when it detects an out-of-bounds subscript. If the compiler cannot detect the out-of-bounds subscript (for example, if the subscript includes a function reference), a message is issued for out-of-bound subscripts when your program runs, but the program is allowed to complete execution.
Bounds checking does not inhibit vectorization but typically increases program run time. If an array's last dimension declarator is *, checking is not performed on the last dimension's upper bound. Arrays in formatted WRITE and READ statements are not checked.
Note: Array bounds checking does not prevent operand range errors that result when operand prefetching attempts to access an invalid address outside an array. Bounds checking is needed when very large values are used to calculate addresses for memory references.
If bounds checking detects an out-of-bounds array reference, a message is issued for only the first out-of-bounds array reference in the loop. For example:
DIMENSION A(10)
MAX = 20
A(MAX) = 2
DO 10 I = 1, MAX
A(I) = I
10 CONTINUE
CALL TWO(MAX,A)
END
SUBROUTINE TWO(MAX,A)
REAL A(*) ! NO UPPER BOUNDS CHECKING DONE
END |
The following messages are issued for the preceding program:
lib-1961 a.out: WARNING Subscript 20 is out of range for dimension 1 for array 'A' at line 3 in file 't.f' with bounds 1:10. lib-1962 a.out: WARNING Subscript 1:20:1 is out of range for dimension 1 for array 'A' at line 5 in file 't.f' with bounds 1:10. |
The FREE and FIXED directives specify whether the source code in the program unit is written in free source form or fixed source form. The FREE and FIXED directives override the -f option, if specified, on the command line. The formats of these directives are as follows:
|
These directives apply to the source file in which they appear, and they allow you to switch source forms within a source file.
You can change source form within an INCLUDE file. After the INCLUDE file has been processed, the source form reverts back to the source form that was being used prior to processing of the INCLUDE file.
Note: The source preprocessor does not recognize the FREE and FIXED directives. These directives must not be specified in a file that is submitted to the source preprocessor. To specify source form, specify -f fixed or the -f free option on the ftn command line.
| Prev Section | Table of Contents | Title Page | Index | Next Section |
| Scalar Optimization Directives | Up one level | Storage Directives |