(j3.2006) allocatable function question

dick.hendrickson at att.net dick.hendrickson
Mon Jul 20 16:45:25 EDT 2009


There was a question on comp.lang.fortran about when allocatable function
results are deallocated.  F2003, 6.3.3.1 (page 116, line 1) says that the
result variable of the allocatable function is deallocated after execution
of the innermost executable construct containing the reference.  So, in
       x = F(y)
the result is deallocated after the assignment takes place.

But, in 
     x = F(y) + F(z)
when are the results deallocated?  Assuming the processor evaluates  
F twice, how can it deallocate both after the assignment?  F must contain
an ALLOCATE statement for its result variable.  Doesn't that mean that
the result variable is already allocated on the second entry into F?  If so,
it's an error to try and ALLOCATE it the second time.   

If there are actually different result variables for the two invocations, then
there is no problem; they can both be deallocated after the assignment.  But,
then why does 6.3.3.1 say things are deallocated after the innermost
construct?  If each result is really a separate thing, there's no need to specify
when, or even if, the results are deallocated.  

The next paragraph has a similar statement for allocatable functions
appearing in specification statements.

If there is a problem with allocatable functions, then there might be a
similar problem for finalizable function results; the wording is essentially the
same for when functions get finalized.

Dick Hendrickson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://j3-fortran.org/pipermail/j3/attachments/20090720/c72d212a/attachment.html 



More information about the J3 mailing list