language lawyer question
Paul Brook
paul@codesourcery.com
Fri Jan 21 14:45:00 GMT 2005
On Friday 21 January 2005 06:10, Paul Thomas wrote:
> The problem lies in this function:
>
> function getOa(ob) result(oa)
> type(objB),target :: ob
> type(objA), pointer :: oa
> oa=>ob%oa
> end function getOa
From the draft F95 standard:
Section 14.6.2.1.3 "Events that cause the association status of a pointer to
become undefined":
"(3) Execution of a RETURN or END statement that causes a pointer's target to
become undefined."
Section 14.7.6 "Events that cause variables to become undefined":
"(3) The execution of a RETURN or END statement within a subprogram causes all
variables local to its scoping unit [...] to become undefined [...]"
None of the exceptions listed apply to the case above.
Thus the return value of getOa (oa) has undefined pointer association status
after getOa has returned.
A compiler might allocate ob on the stack, so it will be freed when getOa
returns.
One way to avoid this is to mark ob as SAVEd
Paul
More information about the Fortran
mailing list