Currently, the standard forbids any reference to a subobject of an
optional dummy argument which is not present. Wouldn't it make
sense to relax this constraint and allow such references as actual
arguments for optional dummy arguments.
Consider the typical case
interface p
module procedure p_scalar, p_vector
end interface
subroutine p_vector (v, w)
integer, dimension(:), intent(inout) :: v
integer, dimension(:), intent(in), optional :: w
integer :: i
do i = 1, size (v)
call p_scalar (v(i), w(i))
end do
end subroutine p_vector
subroutine p_scalar (v, w)
integer, intent(inout) :: v
integer, intent(in), optional :: w
integer :: i
if (present (w)) then
v = w
else
v = 0
end if
end subroutine p_scalar
As written, this code is not legel, if p_vector is ever called
without the second argument.
In this trivial example, one could either use an elemental
procedure (as long as p_scalar is pure) or insert a test
`if(present(w))'. The first solution is not generally applicable
and the latter becomes exponentially tedious (and error prone and
hard to read) when the number of optional arguments increases.
--
Thorsten Ohl, Physics Department, TU Darmstadt -- [log in to unmask]
http://crunch.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|