VALUE (Fortran 2003)
Purpose
The VALUE attribute specifies an argument association between a dummy and an actual argument. This association allows you to pass the dummy argument with the value of the actual argument. This Fortran 2003 pass by value implementation provides a standard conforming option to the %VAL built-in function.
An actual argument and the associated dummy argument can change independently. Changes to the value or definition status of the dummy argument do not affect the actual argument. A dummy argument with the VALUE attribute becomes associated with a temporary variable with an initial value identical to the value of the actual argument.
Syntax
Rules
You must specify the VALUE attribute for dummy arguments only.
You must not use the %VAL or %REF built-in functions to reference a dummy argument with the VALUE attribute, or the associated actual argument.
A referenced procedure that has a dummy argument with the VALUE attribute must have an explicit interface.
A dummy argument with the VALUE attribute can be of character type .
- Dummy procedures
- Polymorphic items
Assumed-rank objects
You can specify the VALUE attribute on an
array dummy argument that has either assumed-shape or explicit-shape. However, you cannot specify
the VALUE attribute on an array dummy argument that has deferred-shape,
assumed-size, or implied-shape.
| INTENT(IN) | OPTIONAL | TARGET |
If a dummy argument has both the VALUE and TARGET attributes, any pointers associated with that dummy argument become undefined after the execution of the procedure.
Examples
Program validexm1
integer :: x = 10, y = 20
print *, 'before calling: ', x, y
call intersub(x, y)
print *, 'after calling: ', x, y
contains
subroutine intersub(x,y)
integer, value :: x
integer y
x = x + y
y = x*y
print *, 'in subroutine after changing: ', x, y
end subroutine
end program validexm1
before calling: 10 20
in subroutine after changing: 30 600
after calling: 10 600
