(j3.2006) interesting CONTIGUOUS pointer example

Bill Long longb
Fri Mar 22 15:51:43 EDT 2013


Recently posted on the web:

integer,pointer,contiguous :: ptr1(:)
integer :: xx
xx = fun1(ptr1)
xx = fun2(ptr1)
contains

function fun1(pdmy)
integer :: fun1
integer,pointer :: pdmy(:)
integer,target :: trg(10)
trg = 10
trg(2:8:2) = 20
pdmy=>trg(2:8:2) !!!! pdmy is associated with non contiguous target.
fun1 = 1
end function

function fun2(dmy)
integer :: fun2
integer:: dmy(4)
print*,dmy
fun2 = 2
end function
end


The program should certainly be invalid.  Nominally, at the end of fun1 
the dummy pointer's association status becomes undefined since its 
target goes away, so dmy in fun2 is undefined, and hence unprintable.

However, suppose the declaration in fun1 was changed from

integer,target :: trg(10)

to

integer,target,save :: trg(10)

At that point, the pointer does not go undefined on return, but the 
associated actual argument is contiguous, which is a problem.  I'm 
trying to find somewhere where we clearly say that, on return from fun1 
the actual argument pointer becomes associated with the target of the 
corresponding dummy pointer.  That would specifically illegal because of 
the contiguous attribute on the actual.

Would it help to explicitly say that a dummy data pointer that 
corresponds to an actual data pointer with the CONTIGUOUS attribute 
shall not be associated with a non-contiguous target when the subprogram 
completes?

Cheers,
Bill



-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list