(j3.2006) allocatable function question

Bill Long longb
Mon Jul 20 17:28:06 EDT 2009



dick.hendrickson at att.net wrote:
> 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.  


This is effectively the case.  See Note 12.37 Pages 280-281 in f03. 
Result variables could not be static and still have recursive functions 
work.  Indeed, we prohibit SAVE for a function result (C517, [72:39]).

Cheers,
Bill




> 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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3

-- 
Bill Long                                   longb at cray.com
Fortran Technical Support    &              voice: 651-605-9024
Bioinformatics Software Development         fax:   651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120





More information about the J3 mailing list