(j3.2006) Change from Fortran 2003 to Fortran 2008

Bill Long longb
Fri May 18 16:11:35 EDT 2012



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.

Cheers,
Bill


> 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
>
> _______________________________________________
> 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./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list