Print

Print


Consider the following simple program:

   integer, pointer :: x => null()
   integer, target :: y = 42
   call sub1( x, y )
   print *, "After sub1: associated(x)? ", associated(x), "; expected is T"
   call sub2( x )
   print *, "After sub2: associated(x)? ", associated(x), "; expected is ?"
contains
   subroutine sub1( ptr, tgt )
      integer, pointer, intent(out) :: ptr
      integer, target, intent(in)   :: tgt
      ptr => tgt
   end subroutine
   subroutine sub2( ptr, tgt )
      integer, pointer, intent(out)         :: ptr
      integer, target, intent(in), optional :: tgt
      if ( present(tgt) ) ptr => tgt
   end subroutine
end

What should be the association status of actual argument x following
the invocation of the subprogram sub2 per current Fortran standard?
Is it processor-dependent?

Readers will note the standard says in section 12.5.2.7 Pointer dummy
variables, para 4 of 10-007r1, "If the dummy argument has INTENT
(OUT), the pointer association status of the actual argument becomes
undefined on invocation of the procedure."  If the subprogram then
fails to associate the dummy argument with a valid target, does the
actual argument remain undefined upon procedure exit?

Thanks,
Vipul Parekh

########################################################################

To unsubscribe from the COMP-FORTRAN-90 list, click the following link:
https://www.jiscmail.ac.uk/cgi-bin/webadmin?SUBED1=COMP-FORTRAN-90&A=1