(j3.2006) interesting CONTIGUOUS pointer example
Robert Corbett
robert.corbett
Fri Mar 22 18:52:26 EDT 2013
On 03/22/13 12:51, Bill Long wrote:
> 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.
The program is invalid. Clause 16.5.2.6 states
While two pointers are name associated,
storage associated, or inheritance associated,
if the association status of one pointer
changes, the association status of the other
changes accordingly.
The dummy argument pdmy is name associated with
ptr1 during the execution of fun1. When pdmy
becomes associated with trg(2:8:2), ptr1 also
becomes associated with trg(2:8:2), which is
prohibited by paragraph one of Clause 5.3.7.
> 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
>
>
>
More information about the J3
mailing list