(j3.2006) functions with allocatable result variables
Robert Corbett
robert.corbett
Sat Apr 14 06:06:48 EDT 2012
Suppose a function has an allocatable result variable.
Paragraph 3 of Clause 12.6.2.2 [307:18-19] states
If the result variable is not a pointer,
its value shall be defined by the function.
For the value of an allocatable variable to be defined,
the variable must be allocated. Is it intended that an
allocatable result variable must be allocated on return
from the function? The standard works better if the
result variable is required to be allocated on return,
but I am not certain that requirement is intentional.
Paragraph 4 of Clause 6.7.3.2 [130:28 - 131:2] states
If an executable construct construct references
a function whose result is either allocatable
or a structure with a subobject that is
allocatable, and the function reference is
executed, an allocatable result and any
subobject that is an allocated allocatable
entity in the result returned by the function
is deallocated after execution of the innermost
executable construct containing the reference.
Suppose F is a function whose result is allocatable.
Consider the code fragment
DO, WHILE(ALLOCATED(F())
<block>
END DO
Assume the <block> includes a transfer of control out
of the DO construct. My reading of the statement cited
above is that the allocated results of the function
reference remain allocated until execution of the
DO construct terminates, at which time, all of the
allocated results are deallocated. Is that intended?
There is a similar, but less important, issue for
IF constructs. Oracle Solaris Studio Fortran does
not work as the standard requires for these cases.
Robert Corbett
More information about the J3
mailing list