 |
» |
|
|
 |
Specifies the intended use of dummy arguments. SyntaxA type declaration statement with the INTENT
attribute is:7 type , attrib-list :: dummy-arg-name-list |
- type
is a valid type specification (INTEGER,
REAL, LOGICAL,
CHARACTER, TYPE
(name),
etc.). - attrib-list
is a comma-separated list of attributes including
INTENT(intent-spec)
and the optional attributes compatible with it, shown below: - intent-spec
is one of IN,
OUT, or INOUT.
(The form IN OUT
is valid.) - dummy-arg-name-list
is a comma-separated list of subprogram dummy arguments
to which intent-spec is to apply.
The syntax of the INTENT
statement is: INTENT (intent-spec) [::] dummy-arg-name-list |
DescriptionThe INTENT
attribute declares whether a dummy argument is intended for transferring
a value into a procedure, or out of it, or both. The INTENT
attribute helps detect the use of arguments inconsistent with their
intended use, and may also assist the compiler in generating more
efficient code. If a dummy argument has intent IN,
the procedure must not change it or cause it to become undefined.
If the actual argument is defined, this value is passed in as the
value of the dummy argument. If a dummy argument has intent OUT,
the corresponding actual argument must be definable; that is, it
cannot be a constant. When execution of the procedure begins, the
dummy argument is undefined; thus it must be given a value before
it is referenced. The dummy argument need not be given a value by
the procedure. If a dummy argument has intent INOUT,
the corresponding actual argument must be definable. If the actual
argument is defined, this value is passed in as the value of the
dummy argument. The dummy argument need not be given a value by
the procedure. The following points should also be noted: Intent specifications apply only to
dummy arguments and may only appear in the specification part of
a subprogram or interface body. If there is no intent specified for an argument
in a subprogram, the limitations imposed by the actual argument
apply to the dummy argument. For example, if the actual argument
is an expression that is not a variable, the dummy argument must
not redefine its value. The intent of a pointer dummy argument must not
be specified.
Examples! x, y, and z are dummy arguments SUBROUTINE electric (x, y, z) REAL, INTENT (IN) :: x, y ! x and y are used only for input ! z is used for input and output COMPLEX, INTENT (INOUT), TARGET :: z(1000) ... SUBROUTINE pressure (true, tape, a, b) USE a_module TYPE(ace), INTENT(IN) :: a, b ! a and b are only for input INTENT (OUT) true, tape ! true and tape are for output ... SUBROUTINE lab_ten (degrees, x, y, z) COMPLEX, INTENT(INOUT) :: degrees REAL, INTENT(IN), OPTIONAL :: x, y INTENT(IN) z ... PROGRAM pxx CALL electric (a+1, h*c, d) ! First subroutine defined above CALL lab_ten (dg, e, f, g+1.0) END PROGRAM pxx |
Related statementsFUNCTION
and SUBROUTINE Related conceptsFor related information, see the following:
|