Thanks to Michael Metcalf for his answer to my recent
question about the interpretation of INTENT for pointer
components of derived type dummy arguments.
If I understood his answer correctly, one ought to be able
to modify the value of the target of a pointer component
of an intent(in) derived type dummy argument, as long as
the association status of the pointer itself is not modified
(what a mouthful!). This seems to be almost true. Consider
the following example:
module my_type
type :: box
real, pointer :: array(:) !=> null()
end type box
contains
subroutine fill (this)
type(box), intent(in) :: this
! INTENT(IN) applies to the pointer association status, not the target,
call random_number (this % array) ! so this is okay, right?
end subroutine fill
subroutine psum (this)
type(box), intent(in) :: this
! As above, INTENT(IN) is correct
call partial_sum (this % array) ! so this should be okay too, right?
end subroutine psum
subroutine partial_sum (array)
real, dimension(:), intent(inout) :: array
integer :: j
do j = 2, size(array)
array(j) = array(j) + array(j-1)
end do
end subroutine partial_sum
end module my_type
I have ready access to two compilers (one F90, the other F95) both
of which I consider to be better than the norm. Neither complain
about the call in FILL to RANDOM_NUMBER, but both complain about the
call in PSUM to PARTIAL_SUM, because they regard this%array (the
target) as intent(in) while the corresponding dummy argument is
intent(inout). Frankly I don't see the difference between the former
and latter cases. Help!
Neil
--
Neil N. Carlson [log in to unmask]
Motorola Computational Materials Group [log in to unmask], [log in to unmask]
Los Alamos National Laboratory Voice: 505-665-1220
Mailstop B221, Los Alamos, NM 87545 FAX: 505-665-5757
|