(j3.2006) a question on c_f_pointer call
Jim Xia
jimxia
Wed Aug 25 15:27:02 EDT 2010
j3-bounces at j3-fortran.org wrote on 08/25/2010 03:18:40 PM:
> [image removed]
>
> Re: (j3.2006) a question on c_f_pointer call
>
> Bill Long
>
> to:
>
> fortran standards email list for J3
>
> 08/25/2010 03:19 PM
>
> Sent by:
>
> j3-bounces at j3-fortran.org
>
> Please respond to longb, fortran standards email list for J3
>
>
>
> Jim Xia wrote:
> >
> > 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
> >
>
> This one looks OK.
>
> > 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
> >
>
> This is no legal. See 6.7.3.3 'Deallocation of pointer targets'. In
> particular "Deallocating a pointer ... whose target was not created by
> an ALLOCATE statement causes an error condition in the DEALLOCATE
> statement".
>
>
> > 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
> >
>
> Same section. "If a pointer is associated with an allocatable entity,
> the pointer shall not be deallocated."
>
> Cheers,
> Bill
>
>
> >
> > 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,
What does Cray compiler produce for the three cases?
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/9a625ab7/attachment-0001.htm>
More information about the J3
mailing list