(j3.2006) Did we intend to prohibit this?
Van Snyder
Van.Snyder
Fri Mar 10 17:00:04 EST 2017
On Fri, 2017-03-10 at 21:47 +0000, Clune, Thomas L. (GSFC-6101) wrote:
> > On Mar 10, 2017, at 2:09 PM, Van Snyder <Van.Snyder at jpl.nasa.gov> wrote:
> >
> > On Fri, 2017-03-10 at 16:13 +0900, Cohen Malcolm wrote:
> >>
> >>> So how does it get deallocated?
> >>
> >> "it" is not a variable, so does not get deallocated (in the Fortran
> >> language sense of "deallocated").
> >>
> >> You know what the function result variable is, and it is not the value
> >> that is returned by the function, nor has it ever been. The result
> >> variable is what gets deallocated.
> >
> > So what does 9.7.3.2p4 mean?
> >
> > "If an executable construct references a function whose result
> > is allocatable or has an allocatable subobject, and the function
> > reference is executed, an allocatable result and any allocated
> > allocatable subobject of the result is deallocated after
> > execution of the innermost executable construct containing the
> > reference."
> >
> > If the result variable is in fact what gets deallocated, even though the
> > word "variable" does not appear in 9.7.3.2p4, then the result variable
> > of F(X) in
> >
> > call move_alloc ( f(x), v )
> >
> > IS a variable, right? So what's the problem with executing it?
>
> The result variable of F(X) is not in the expression you provide.
> Outside of F all you can ?see" is the result _value_.
According to 9.7.3.2p4, whatever the function result is, it must be
allocatable, or it couldn't be deallocated. So what's the problem with
call move_alloc ( f(x), v )
> I think that what you probably want in this situation is:
>
> allocate(v, source=f(x))
If it's not known not to be allocated, one would need the somewhat more
verbose
if ( allocated(v) ) deallocate ( v )
allocate(v, source=f(x))
As of F08, this is no different from
v = f(x)
This brings me back to the other question in my original message, which
Malcolm erroneously interpreted as a question about the standard, rather
than a question about what processors actually do:
In
v = f(x)
where v and the result of F() are allocatable, do processors typically
reallocate v with the correct size if necessary, copy the value of f(x)
into it, and deallocate the result of f(x), or do they do what
call move_alloc ( f(x), v )
would obviously have done if it were allowed?
More information about the J3
mailing list