On 9/19/2016 9:06 AM, FortranFan wrote:
> On Monday, September 19, 2016 at 6:42:17 AM UTC-4, Arjen Markus wrote:
>> Hello,
>>
>> I ran into a little riddle the other day. In Fortran 2003 it is permitted to associate a "2D" pointer to a 1D array, something like:
>>
>> real, dimension(100), target :: array
>> real, dimension(:,:), pointer :: matrix
>>
>> matrix(1:20,1:5) => array
>>
>> However, I cannot check that the pointer "matrix" is associated to the array "array". A statement like:
>>
>> write( *, '(a,l)' ) 'Associated? ', associated(matrix,array)
>>
>> causes the compiler to complain - the number of dimensions for both arguments must match.
>>
>> How can I verify this type of association?
>
> Perhaps an oversight in the standard? That the ASSOCIATED function (which was what introduced in Fortran 90, I think) was not updated to reflect the "new feature" of remapping to rank-one arrays permitted in Fortran 2003 revision?
No, not an oversight in the standard, but rather a compiler that didn't
keep up with the change.
The wording in the F2008 standard, not much different from F2003, is:
"TARGET (optional) shall be allowable as the data-target or proc-target
in a pointer assignment statement (7.2.2) in which POINTER is
data-pointer-object or proc-pointer-object ."
There's no mention of rank here. Rather, you have to go look at the
description of pointer assignment to see what is "allowable". In F2003,
it said:
C720 (R735) If bounds-remapping-list is specified, data-target shall
have rank one; otherwise, the ranks of data-pointer-object and
data-target shall be the same
F2008 removes the restriction that the data-target be rank one and
simply says:
C718 (R733) If bounds-remapping-list is not specified, the ranks of
data-pointer-object and data-target shall be the same.
In any case, if the pointer assignment is "allowable", then so is
ASSOCIATED. I note that Intel Fortran gives the bogus error about the
ranks needing to match and will report that to the developers.