[J3] [EXTERNAL] Re: Changing address of an allocatable on assignment when shapes match
Bill Long
longb at cray.com
Sat Aug 24 12:21:32 EDT 2019
> On Aug 24, 2019, at 10:21 AM, Vipul Parekh via J3 <j3 at mailman.j3-fortran.org> wrote:
>
> On Sat, Aug 24, 2019 at 3:43 AM Van Snyder via J3
> <j3 at mailman.j3-fortran.org> wrote:
>>
>> .. the deallocation before the revised allocation
>> causes all associated pointers to become undefined. The reallocation is
>> fine and standard conforming, even if the <variable> has the TARGET
>> attribute. What's not allowed is using a formerly associated pointer
>> after it becomes undefined -- no matter how it became undefined.
>>
>
> Under the circumstances then, is the following code conformant with
> the standard? I fail to see why it would not be, so any feedback will
> be very useful for me.
>
> integer, allocatable, target :: foo(:)
> integer, pointer :: bar(:)
> foo = [ 1 ]
> bar => foo
> print *, "bar = ", bar
> foo = [ 1, 2 ]
> bar => foo ! Important Statement
> print *, "bar = ", bar
> end
>
The code looks OK because every time you newly allocate foo the pointer assignment bar=>foo is redone before bar is referenced. If the statement I labeled as “Important Statement” above were removed, then the code would not be conforming. In that case in the final print statement, bar would not be associated, since the first foo, to which bar was associated, has been deallocated, and bar was not subsequently associate with something else (like, in particular, the new foo). You are not allowed to reference a pointer that is not associated.
Cheers,
Bill
> Thanks,
> Vipul Parekh
Bill Long longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
More information about the J3
mailing list