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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Functions and Subroutines<br />

4. An external procedure name.<br />

5. A dummy procedure name.<br />

The actual arguments of an external function reference must match the order, number and type of the<br />

corresponding dummy arguments. If a subroutine is an actual argument, then type agreement is not<br />

required since a subroutine has no type.<br />

12.4.3 External Function Subprogram Restrictions<br />

1. The name of an external function is a global name and must not be the same as any other global<br />

name or name local to the subprogram whose name is that of the external function. Note that the<br />

external function name is treated as a variable within the external function subprogram.<br />

2. The name of a dummy argument is a name local to the subprogram and must not appear in an<br />

EQUIVALENCE, PARAMETER, SAVE, INTRINSIC or DATA statement within the same<br />

subprogram. It may appear in a COMMON statement only as the name of a common block.<br />

3. The name of the external function can in no way, directly or indirectly, be referenced as a<br />

subprogram from within the subprogram it defines. It can appear in a type statement to establish<br />

its type only if the type has not been established in the FUNCTION statement.<br />

12.5 Subroutines<br />

A subroutine is a program unit that has a SUBROUTINE statement as it first statement. It is defined<br />

externally to the program units that reference it. The form of a SUBROUTINE statement can be found in<br />

the chapter entitled "<strong>FORTRAN</strong> Statements" on page 9.<br />

A subroutine differs from a function in that it does not return a result and hence has no type associated with<br />

it. However, it is possible to return values from a subroutine by defining or redefining the dummy<br />

arguments of the subroutine.<br />

12.5.1 Referencing a Subroutine: The CALL Statement<br />

Unlike a function, a subroutine cannot appear in an expression. Subroutines are referenced by using a<br />

CALL statement. See the chapter entitled "<strong>FORTRAN</strong> Statements" on page 9 for details on the CALL<br />

statement. When a CALL statement is executed, the following steps are performed.<br />

1. The actual arguments are evaluated.<br />

2. The actual arguments are associated with the corresponding dummy arguments.<br />

3. The subroutine is executed.<br />

A subroutine can be called from any subprogram but must not be called by itself, indirectly or directly.<br />

12.5.2 Actual Arguments for a Subroutine<br />

Each actual argument in a subroutine call must be one of the following.<br />

1. Any expression except a character expression involving the concatenation of an operand whose<br />

length specification is (*) unless the operand is a symbolic constant.<br />

Subroutines 273

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

Saved successfully!

Ooh no, something went wrong!