FPT and WinFPT Reference Manual - Command-line Commands

| SimCon Home | Reference Manual Home |


SEPARATE DO AND GOTO DESTINATION LABELS

Syntax:

[DO NOT] SEPARATE DO AND GOTO [STATEMENT] [DESTINATION] LABELS

Function:

A GOTO, arithmetic IF or alternate return may transfer control to the statement label which terminates a DO loop. There are two possible situations:

  1. where the GOTO statement is inside the scope of the DO loop.

  2. where the GOTO statement is outside the DO loop.

FPT modifies all labelled statements which are referenced both by DO and by GOTO statements to separate the target labels. New labels are generated, and FPT therefore renumbers all statement labels so as to maintain a consistent order throughout the program. Please see RENUMBER LABELS for a description of this process.

If the GOTO statement is inside the DO loop, the expected behaviour is that the current iteration of the DO loop ends and the next iteration begins. Many compilers have been tested to verify this behaviour and no exceptions have been observed. FPT therefore modifies the labelled statement as shown in the first example below.

  1. If the label is attached to an executable statement, it is removed and attached to a new CONTINUE statement which terminates the DO loop.

  2. A new labelled CONTINUE statement is generated as the target for the GOTO statement, and this is inserted before the CONTINUE statement at the end of the DO loop.

If the GOTO statement is outside the DO loop, the behaviour depends on the compiler in use. The following have been observed:

  1. The statement at the end of the loop is not executed. Control enters the DO loop at the DO statement, initialising the DO loop control variables (e.g. VAX/VMS).

  2. The statement at the end of the loop is executed. Control then remains in the DO loop without initialising the DO loop control variable (e.g. DEC VMS for Alpha AXP).

  3. The compiler generates a warning or error for a jump into a DO loop (e.g. DEC Visual Fortran).

  4. The statement at the end of the DO loop is executed, and control then continues from that statement without entering the DO loop (Gould-SEL (now Encore) Concept-32). FPT modifies the code on the assumption that this is the intended behaviour. It is the intended behaviour in most of the code where the construct has been found.

FPT modifies the code as shown in the second example below. A new labelled CONTINUE statement is written after the end of the DO loop, and this becomes the target for the GOTO statement.

Where to use this command:

Operating system command line

Yes


Configuration file, config.fsp

Yes


Specification (FSP) files, *.fsp

Yes


Interactively, to FPT> prompt:

Yes


Interactive command files

Yes


Embedded in the Fortran code

Yes


Default:

No change is made by default.

Examples:

In the code shown below, the GOTO statement is within the DO loop.

DO 100 I=1,10 IF (A(I) .GT. CRIT) GOTO 100 A(I)=CRIT 100 CALL STATENT(A(I))

FPT rewrites the code:

DO 1010 I=1,10 IF (A(I) .GT. CRIT) GOTO 1000 A(I)=CRIT 1000 CONTINUE CALL STATENT(A(I)) 1010 CONTINUE !-------------^--------------------------------------------------------------- !!! FPT - 2311 GOTO from inside loop directed to different label !-----------------------------------------------------------------------------

In the following example, the GOTO is outside the loop:

IF (INIT .EQ. -1) GOTO 220 DO 220 J=1,5 220 C(J)=0.0

Note that this code is legal on a number of systems. FPT rewrites the code:

IF (INIT .EQ. -1) GOTO 1040 DO 1030 J=1,5 C(J)=0.0 1030 CONTINUE 1040 CONTINUE !-------------^--------------------------------------------------------------- !!! FPT - 2311 GOTO from outside loop directed to different label !-----------------------------------------------------------------------------

See also:

RENUMBER LABELS


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