(j3.2006) interp fodder from comp.lang.fortran
Van Snyder
Van.Snyder
Thu Sep 3 22:05:51 EDT 2015
It wasn't clear from Malcolm's message what would be changed to "have
the same rank."
If there is a specific elemental subroutine with a generic ASSIGNMENT(=)
interface, and the variable is allocatable, meets 7.2.1.4p2(1-3), the
kind type parameters of x1 and x2 match those of d1 and d2, and x1 has
the same rank as x2, defined assignment ought to be used.
The requirement in 7.2.1.4p2(4) that type parameters match ought to be
that kind type parameters match, length type parameters of x2 and d2
match, nondeferred length type parameters of x1 and d1 match, and if x1
is allocatable and allocated then deferred length type parameters of x1
and d1 match.
Once the decision is made to use an elemental subroutine to do the
defined assignment, and x1 is allocatable, and has different shape,
dynamic type, or length type parameters from x2, it ought to be
deallocated. Then, if x1 is or becomes deallocated, it ought to be
allocated with the same shape, dynamic type, and length parameters as
x2, as is done in 7.2.1.3p3.
It's not obvious to me how the processor can decide whether to do
defined or intrinsic assignment if length type parameters are included
in 7.2.1.4p2(4).
Indeed, it's not clear how a processor can decide not to do defined
assignment if x1 is not allocatable but x1 and x2 are conformable. The
relationship of the shapes of x1 and x2 should not (indeed apparently
cannot) enter into the decision. If x1 and x2 are arrays of the same
rank but not conformable, and x1 is not allocatable, this must
necessarily be a runtime error, as in the case of any elemental
reference, not a compile-time desideratum whether to use defined
assignment.
On Thu, 2015-09-03 at 03:45 -0700, Robert Corbett wrote:
> 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
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
More information about the J3
mailing list