(j3.2006) interp fodder from comp.lang.fortran
Robert Corbett
robert.corbett
Thu Sep 3 06:45:04 EDT 2015
A post to c.l.f. by Andrew Baldwin shows what appears
to be a flaw in the standard regarding assignments to
allocatable variables. Consider the assignment
statement
A = B
where A is an allocatable array variable and B is an
array expression of the same rank, type, and kind.
Suppose there is an elemental subroutine for the
type and kind of A and B and a generic interface
that specifies ASSIGNMENT(=) that includes the
subroutine as a specific subroutine. Then if A and
B have the same shape, the assignment is done as a
defined assignment, but if A and B have different
shapes, the assignment is done as an intrinsic
assignment that deallocates and then allocates A.
Clause 7.2.1.4 of the Fortran 2008 standard sets
out the conditions for when a defined assignment is
performed. The key part of the clause for this
example is item (5) which states
(b) the subroutines is elemental, x[1] and
x[2] are conformable, and there is no
other subroutine that defines the
assignment.
Two arrays are conformable if they have the same
shape. Therefore, whether the assignment is done
as a defined assignment or an intrinsic assignment
depends on whether A and B have the same shape.
The problem was introduced in the Fortran 2003
standard. In Fortran 90 and Fortran 95, the
array variable A was required to be allocated and
the shapes of A and B were required to be the same
for both defined and intrinsic assignments.
Fortran 2003 relaxed the restrictions for
intrinsic assignments, but not for defined
assignments. The obvious fix for the problem is
to relax the restrictions for defined assignments
as well.
Robert Corbett
More information about the J3
mailing list