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 />

12.4 External Functions<br />

An external function is a program unit that has a FUNCTION statement as its first statement. It is defined<br />

externally to the program units that reference it. The form of a FUNCTION statement is defined in the<br />

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

The name of an external function is treated as if it was a variable. It is through the function name that the<br />

result of an external function becomes defined. This variable must become defined before the execution of<br />

the external function is completed. Once defined, it can be referenced or redefined. The value of this<br />

variable when a RETURN or END statement is executed is the result returned by the external function.<br />

Example:<br />

INTEGER FUNCTION VECSUM( A, N )<br />

INTEGER A(N), I<br />

VECSUM = 0<br />

DO 10 I = 1, N<br />

VECSUM = VECSUM + A(I)<br />

10 CONTINUE<br />

END<br />

If the variable representing the return value of the external function is of type CHARACTER with a length<br />

specification of (*), it must not be the operand of a concatenation operator unless it appears in a character<br />

assignment statement.<br />

It is also possible for an external function to return results through its dummy arguments by assigning to<br />

them. The following example demonstrates this.<br />

External Functions 271

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

Saved successfully!

Ooh no, something went wrong!