(j3.2006) Change from Fortran 2003 to Fortran 2008
Robert Corbett
robert.corbett
Fri May 18 15:22:18 EDT 2012
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.
In Fortran 2003, the function reference F(P) is not a variable.
Therefore, the construct entity Y is associated with the value
1.0, not with the variable X.
Robert Corbett
More information about the J3
mailing list