Fortran Programming Guide

Special Compiler Options

Some compiler options are useful for debugging. They check subscripts, spot undeclared variables, show stages of the compile-link sequence, display versions of software, and so on.

The Solaris linker has additional debugging aids. See ld(1), or run the command ld -Dhelp at a shell prompt to see the online documentation.

Subscript Bounds (-C)

The -C option adds checks for out-of-bounds array subscripts.

If you compile with -C, the compiler adds checks at runtime for out-of-bounds references on each array subscript. This action helps catch some situations that cause segmentation faults.

Example: Index out of range:


demo% cat indrange.f
      REAL a(10,10)
      k = 11
      a(k,2) = 1.0
      END
demo% f77 -C -silent indrange.f
demo% a.out
 Subscript out of range on file indrange.f, line 3, procedure MAIN. 
 Subscript number 1 has value 11 in array a. 
 Abort (core dumped) 
demo%

f77: Undeclared Variable Types (-u)

The -u option checks for any undeclared variables. (Not available with f90.)

The -u option causes all variables to be initially identified as undeclared, so that all variables that are not explicitly declared by type statements, or by an IMPLICIT statement, are flagged with an error. The -u flag is useful for discovering mistyped variables. If -u is set, all variables are treated as undeclared until explicitly declared. Use of an undeclared variable is accompanied by an error message.

Version Checking (-V)

The -V option causes the name and version ID of each phase of the compiler to be displayed. This option can be useful in tracking the origin of ambiguous error messages and in reporting compiler failures, and to verify the level of installed compiler patches.