(j3.2006) Change from Fortran 2003 to Fortran 2008
Robert Corbett
robert.corbett
Fri May 18 18:10:30 EDT 2012
On 05/18/12 13:11, Bill Long wrote:
>
>
> On 5/18/12 2:22 PM, Robert Corbett wrote:
>> On 05/18/12 11:01, Bill Long wrote:
>>>
>>>
>>> On 5/18/12 3:14 AM, Robert Corbett wrote:
>>>> The change in the definition of variables in Fortran 2008
>>>> appears to cause a semantic difference. Consider the
>>>> program
>>>>
>>>> FUNCTION F(P)
>>>> POINTER F, P
>>>> F => P
>>>> END
>>>>
>>>> PROGRAM ASSOC
>>>> TARGET X
>>>> POINTER P
>>>> INTERFACE
>>>> FUNCTION F(P)
>>>> POINTER F, P
>>>> END FUNCTION
>>>> END INTERFACE
>>>> X = 1.0
>>>> ASSOCIATE(Y => F(P))
>>>> X = 2.0
>>>> PRINT *, X, Y
>>>> END ASSOCIATE
>>>> END
>>>
>>> I'm not seeing the connection between X and either Y or P. It looks
>>> like Y is a pointer with undefined association status at the beginning
>>> of the associate construct, and nothing later changes that fact.
>>> Printing it is dodgy at best. Did you mean to have
>>>
>>> P => X
>>>
>>> before the ASSOCIATE construct?
>>
>> You are correct. I left out the pointer assignment.
>>
>>> If I add that in, I see
>>>
>>> 2.0 2.0
>>>
>>> as the output. Since Y is pointer associated with X, is that not what
>>> you expect?
>>
>> For Fortran 2008, I agree that your suggested output is correct.
>>
>> For Fortran 2003, I think the output should be
>>
>> 2.0 1.0
>>
>> Paragraph 4 of Clause 16.4.1.5 of the Fortran 2003 standard, which
>> is identical to paragraph 4 of Clause 16.5.1.6 of the Fortran 2008
>> standard, states
>>
>> If the selector is a variable other than an array section
>> having a vector subscript, the association is with the
>> data object specified by the selector; otherwise, the
>> association is with the value of the selector expression,
>> which is evaluated prior to execution of the block.
>>
>
> Same subclauses say (in both standards)
>
> "If the selector has the POINTER attribute, it shall be associated; the
> associate name is associated with the target of the pointer ..."
>
> Isn't the selector a pointer here? It seems like this paragraph applies.
The result of the function reference is a data pointer,
but it does not have the POINTER attribute.
Robert Corbett
More information about the J3
mailing list