(j3.2006) functions with allocatable result variables
Robert Corbett
robert.corbett
Sun Apr 15 22:33:46 EDT 2012
On 4/15/2012 5:46 PM, Malcolm Cohen wrote:
>> 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.
>
> Yes.
>
>> Is it intended that an
>> allocatable result variable must be allocated on return
>> from the function?
>
> That is what the words say, and have said so since 1998. Yes, this
> was intentional.
OK
>> Suppose F is a function whose result is allocatable.
>> Consider the code fragment
>>
>> DO, WHILE(ALLOCATED(F())
>
> This is not conforming. The result of a function reference does not
> have the ALLOCATABLE attribute any more than it has the ASYNCHRONOUS,
> TARGET or VOLATILE attributes.
>
> I quote
> "An entity with the ALLOCATABLE attribute is a ***VARIABLE***"
> (emphasis mine).
Paragraph 4 of clause 6.7.3.2 states
If an executable 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.
If the result of executing a function reference cannot
be "an allocatable result,"that text is defective.
Regardless of whether the result of executing a
function reference can or cannot be an argument of
the intrinsic function ALLOCATED, my question
regarding deallocation of function results stands.
Let F be a function that has an allocatable result
variable. Let G be a function that takes an
argument of the same type as the type of the result
variable of F and returns a LOGICAL result.
Consider the code fragment
DO, WHILE(G(F()))
<block>
END DO
According to the text cited above, the results of
executing F() are deallocated only after execution
of the DO construct is complete. Is that intended?
Do any implementations work that way?
Robert Corbett
More information about the J3
mailing list