A statement function is a procedure defined by a single statement in the same program unit in which the procedure is referenced. It takes the following form:
Named constants and variables used in the expression must have been declared previously in the specification part of the scoping unit or made accessible by use or host association.
If the expression contains a function reference, the function must have been defined previously in the same program unit.
A statement function reference takes the following form:
When a statement function reference appears in an expression, the values of the actual arguments are associated with the dummy arguments in the statement function definition. The expression in the definition is then evaluated. The resulting value is used to complete the evaluation of the expression containing the function reference.
The data type of a statement function can be explicitly defined in a type declaration statement. If no type is specified, the type is determined by implicit typing rules in effect for the program unit.
Actual arguments must agree in number, order, and data type with their corresponding dummy arguments.
Except for the data type, declarative information associated with an entity is not associated with dummy arguments in the statement function; for example, declaring an entity to be an array or to be in a common block does not affect a dummy argument with the same name.
The name of the statement function cannot be the same as the name of any other entity within the same program unit.
Any reference to a statement function must appear in the same program unit as the definition of that function.
A statement function reference must appear as (or be part of) an expression. The reference cannot appear on the left side of an assignment statement.
A statement function must not be provided as a procedure argument.
Examples
The following are examples of statement functions:
REAL VOLUME, RADIUS
VOLUME(RADIUS) = 4.189*RADIUS**3
CHARACTER*10 CSF,A,B
CSF(A,B) = A(6:10)//B(1:5)
The following example shows a statement function and some references to it:
AVG(A,B,C) = (A+B+C)/3.
...
GRADE = AVG(TEST1,TEST2,XLAB)
IF (AVG(P,D,Q) .LT. AVG(X,Y,Z)) STOP
FINAL = AVG(TEST3,TEST4,LAB2) ! Invalid reference; implicit
... ! type of third argument does not
... ! match implicit type of dummy argument
Implicit typing problems can be avoided if all arguments are explicitly typed.
The following statement function definition is invalid because it contains a constant, which cannot be used as a dummy argument:
REAL COMP, C, D, E
COMP(C,D,E,3.) = (C + D - E)/3.
For More Information: