12.4.1 / C.9.5 : TARGET dummy/actual arguments & dangling pointers

From: Joost VandeVondele (jv244_at_cam.ac.uk)
Date: 08/20/04


Date: 20 Aug 2004 07:00:17 -0700

Hi,

below is a testcase for an issue that is confusing me. In the
following code:

 INTEGER, POINTER :: data
 ALLOCATE(data)
 CALL wrap(data)
 write(*,*) ASSOCIATED(data)
CONTAINS
 SUBROUTINE wrap(data)
   INTEGER :: data
   CALL mytarget(data)
 END SUBROUTINE
 SUBROUTINE mytarget(data)
   INTEGER, TARGET :: data
 END SUBROUTINE
END

has the pointer data after the call to wrap become a dangling pointer,
and is a TARGET attribute in the wrap necessary in order to keep it
defined/associated ? It will of course print T on most compilers, but
does a good runtime checker need to complain 'ASSOCIATED function
argument is dangling pointer DATA'

Just in case, the relevant part of C.9.5 seems:
"When execution of a procedure completes, any pointer that remains
defined and that is associated with a dummy argument that has the
TARGET attribute and is either a scalar or an assumed-shape array,
remains associated with the corresponding actual argument if the
actual argument has the TARGET attribute ..."

Thanks,

Joost



Relevant Pages

  • Recursive Algorithm again
    ... the target is to traverse a field of 3 x 3 where it is started at ... There is indicated the pointer 3. ... RECURSIVE SUBROUTINE next_node ... ENDDO ...
    (comp.lang.fortran)
  • problems with recursive algorithm for dynamic time warping
    ... TYPE, POINTER:: n ... RECURSIVE SUBROUTINE next_node ... TYPE, INTENT, TARGET:: n1 ... is there a limit for the number of recursions ?) ...
    (comp.lang.fortran)
  • Re: Merits of fortran
    ... as being a superior language for numeric and scientific programming. ... real, dimension, target:: x ... real, pointer:: py ... subroutine init ...
    (comp.lang.fortran)
  • Re: Procedure Pointer (Components) with no explicit interface and with implicit typing
    ... in principle, I can assign to it either a function nor a subroutine, e.g. ... "7.4.2.2 Procedure pointer assignment" ... "If proc-pointer-object has an implicit interface and is explicitly ... external:: func, sub ...
    (comp.lang.fortran)
  • Re: pointer arguments of subroutines
    ... | I am trying pass a pointer to an array as an argument to a subroutine ... | *local* target is the source of the problem for the moment. ...
    (comp.lang.fortran)