(j3.2006) a question on c_f_pointer call

Jim Xia jimxia
Wed Aug 25 15:02:17 EDT 2010


We're receiving a customer question on pointer's deallocation status for 
FPTR from intrinsic c_f_pointer().  Basically the question is whether user 
should expect successful deallocation of FPTR from call c_f_pointer.  This 
looks pretty much processor dependent since I can't find clear wording in 
the standard specifying the behavior.  To be specific, consider the 
following three cases


case 1
          use, intrinsic :: iso_c_binding
          implicit none
          integer stat
          type(c_ptr) :: cptr
          real(C_DOUBLE), pointer :: p, q
          allocate(p)
          cptr = c_loc(p)
          call c_f_pointer(cptr, q)
          deallocate(q, stat=stat)
          print *, stat
          end

case 2
          use, intrinsic :: iso_c_binding
          implicit none
          integer stat
          type(c_ptr) :: cptr
          real(C_DOUBLE), pointer :: p, q
          real(C_DOUBLE), target :: t
          p => t
          cptr = c_loc(p)
          call c_f_pointer(cptr, q)
          deallocate(q, stat=stat)
          print *, stat
          end

case 3
          use, intrinsic :: iso_c_binding
          implicit none
          integer stat
          type(c_ptr) :: cptr
          real(C_DOUBLE), pointer :: p, q
          real(C_DOUBLE), target, allocatable :: t
          allocate (t)
          p => t
          cptr = c_loc(p)
          call c_f_pointer(cptr, q)
          deallocate(q, stat=stat)
          print *, stat
          end


Note these tests are simplified with all pointers being entities declared 
in main.  In practice these pointers could be dummy pointers and the 
deallocations can happen in different scopes from the c_f_pointer() 
function call.

The question is: does standard require specific behavior on each of the 
DEALLOCATE statement?  I found the standard is vague in this.

Cheers,


Jim Xia

XL Fortran Compiler Test
IBM Toronto Lab at 8200 Warden Ave, Markham, On, L6G 1C7
Phone (905) 413-3444  Tie-line 313-3444
email: jimxia at ca.ibm.com
D2/YF7/8200 /MKM

http://www.ibm.com/software/awdtools/fortran/xlfortran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://j3-fortran.org/pipermail/j3/attachments/20100825/7d47cf4a/attachment.htm>



More information about the J3 mailing list