Statement Function is defined in a program or a subprogram and Statement Function is used internally where it defined. It has a single statement and similar in form to an arithmetic, logical or character assignment statement. In a statement function statement must appear only after the specification statements and before the first executable statement of the program unit in which it is referenced. |
The general form of statement function is: |
fun (list) = e |
where fun is user defined name of the function; |
List is the variable names which are the arguments of the function and must be separated by comma; Arguments of the function may be dummy or actual. |
e is an expression which must be one of the given below: |
· A constant · A variable · An array element reference · An intrinsic function reference · A reference to a statement function for which the statement function statement appears in preceding · lines of the program unit · An external function reference · A dummy procedure reference · An expression enclosed in parentheses that meets all of the requirements specified for the expression e · Arguments of the function may be dummy or actual. |
Example: |
FUND (Y) = Y * Y + 2.2 |
Here FUND is user defined name of the function ie. statement function name. Y is the variable names which are the arguments of the function which is enclosed in between (). This statement function is of real type. Its expression can be written as Y *Y + 2.2 |
Restrictions |
A statement function must appear after the specification statements and before the first executable statement of the program unit in which it is referenced. |
A statement function is not executed at the point where it is specified. |
The actual argument must agree in order, number and type with corresponding dummy arguments. |
A dummy argument cannot be an array or function name. The same argument cannot be specified more than once in the argument list. A statement function cannot be invoked recursively. |
Example of arithmetic statement function: |
PARAMETER ( PI=3.14159) REAL RADIUS, VOLUME SPHERE (R) = 4.0 * (R**3)/ 3.0 READ*,RADIUS VOLUME = SPHERE( RADIUS) |