24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Functions and Subroutines<br />

Example:<br />

SUBROUTINE CALC( U, V )<br />

REAL POLY, X, Y, U, V, Z, CONST<br />

*<br />

* Define a Statement Function.<br />

*<br />

POLY(X,Y) = X**2 + Y**2 + 2.0*X*Y + CONST<br />

*<br />

* Invoke the Statement Function.<br />

*<br />

CONST = 23.5<br />

Z = POLY( U, V )<br />

PRINT *, Z<br />

END<br />

In the previous example, note that after the execution of the statement function, the values of X and Y are<br />

not equal to the value of U and V respectively; they are undefined.<br />

12.2.2 Statement Function Restrictions<br />

1. A statement function is local to the program unit in which it is defined. Thus, a statement<br />

function name is not allowed to appear in an EXTERNAL statement and cannot be passed to<br />

another procedure as an actual argument. The following example illegally attempts to pass the<br />

statement function F to the subroutine SAM.<br />

Example:<br />

* Illegally passing a statement function<br />

* to a subroutine.<br />

PROGRAM MAIN<br />

F(X) = X<br />

.<br />

.<br />

.<br />

CALL SAM( F )<br />

.<br />

.<br />

.<br />

END<br />

2. If a statement function F contains a reference to another statement function G, then the<br />

statement defining G must have previously appeared. In the following example, the expression<br />

defining the statement function F illegally references a statement function G whose defining<br />

statement follows the statement defining F.<br />

Statement Functions 245

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!