Given the discussion thus far on subobjects, is the following code
standard-conforming?
module m
type :: t
type(t), pointer :: i => null()
end type
contains
subroutine sub( o1, o2 )
type(t), pointer, intent(in) :: o1
type(t), pointer, intent(in) :: o2
if ( associated(o2) ) print *, "In sub, o2 is associated"
o1%i => null()
if ( .not. associated(o2) ) print *, "And now o2 is not associated"
end subroutine
end module
program p
use m
type(t), pointer :: o1
type(t), pointer :: o2
allocate( o1, o2 )
o1%i => o2
call sub( o1, o1%i )
if ( associated(o1) ) deallocate( o1 )
if ( associated(o2) ) deallocate( o2 )
end program
Two compilers I tried give the output:
In sub, o2 is associated
And now o2 is not associated
Thanks,
Vipul Parekh
|