FPT and WinFPT Reference Manual - Command-line Commands

| SimCon Home | Reference Manual Home |


INSERT CHECK OF OPTIONAL ARGUMENTS

Syntax:

[DO NOT] INSERT CHECK OF OPTIONAL ARGUMENTS

[DO NOT] INSERT OPTIONAL ARGUMENT[S] CHECK

Function:

FPT checks that every access to each sub-program argument declared with the attribute OPTIONAL is guarded by a tests that the argument is present. If no guard is detected, FPT inserts statements to report the unguarded access at run-time. For example, in the subroutine write_sub:

SUBROUTINE write_sub(t1,t2,t3) CHARACTER*(*) :: t1 CHARACTER*(*),OPTIONAL :: t2,t3 WRITE(6,*) t1 IF (PRESENT(t2)) THEN WRITE(6,*) t2 ENDIF WRITE(6,*) t3 END SUBROUTINE write_sub

the optional argument t3 is not guarded. The failure to guard access to t3 is reported as an error, and the code is modified to:

SUBROUTINE write_sub(t1,t2,t3) CHARACTER*(*) :: t1 CHARACTER*(*),OPTIONAL :: t2,t3 WRITE(6,*) t1 IF (PRESENT(t2)) THEN WRITE(6,*) t2 ENDIF IF (.NOT. PRESENT(t3)) CALL fpt_check_present(7) ENDIF WRITE(6,*) t3 !-------------------^---------------------------------------------------------- !!! FPT - 3741 Unguarded use of OPTIONAL argument which is not always PRESENT !------------------------------------------------------------------------------ END SUBROUTINE write_sub

The routine fpt_check_present is part of the fpt_lib library. The argument is a unique integer identifier for the call-site, and the subroutine counts the unguarded accesses. Note that unguarded accesses to optional arguments which are not present do not necessarily crash the user's program.

FPT also modifies the main program(s) to insert a call to fpt_init_optional_check to initialise the counters, and adds a call to fpt_write_optional_check before every exit point from the program. The subroutine fpt_write_optional_check writes the file fpt_optional_check.txt which contains the count of accesses to optional arguments which were not present.

This command also carries out the checks, and generates the report made by the CHECK OPTIONAL ARGUMENTS command. The report is written to the list file or to the user's screen in interactive mode.

Recommended Use

This command requires the fpt_lib library file fpt_optional_checks.f90 to be included in processing. FPT patches this file to set up the dimensions of the array used to count the unguarded references. It is recommended that the specification file FPTMAIN:insert_optional_checks.fsp is added as the last entry in the fsp file for the program, or is specified as the last component on the operating system command-line. This file contains the necessary commands and file references.

Where to use this command:

Operating system command line

Yes


Configuration file, config.fsp

No


Specification (FSP) files, *.fsp

Yes


Interactively, to FPT> prompt:

No


Interactive command files

No


Embedded in the Fortran code

No


Default:

Checks of optional arguments are not inserted by default.

Related Commands

The command CHECK OPTIONAL ARGUMENTS carries out a static check for unguarded references to optional arguments.


Copyright ©1995 to 2014 Software Validation Ltd. All rights reserved.