(j3.2006) Unlimited poly and pointer component

Daniel C Chen cdchen
Fri Dec 22 20:50:19 EST 2017


Thanks Malcolm for the explanation!

It is clear now!

Thanks,

Daniel

XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran



From:	"Malcolm Cohen" <malcolm at nag-j.co.jp>
To:	"'fortran standards email list for J3'"
            <j3 at mailman.j3-fortran.org>
Date:	12/21/2017 03:12 AM
Subject:	Re: (j3.2006) Unlimited poly and pointer component
Sent by:	"J3" <j3-bounces at mailman.j3-fortran.org>



      Case 1:

      program main
      Type dt
      integer, pointer :: p => NULL()
      end type

      Type(dt) :: d1
      end program

      The standard says
      [527:20]: "A derived-type scalar object is defined if and only if all
      of its nonpointer components are defined."
      [529:28]: "(22) When a pointer becomes associated with a target that
      is defined, the pointer becomes defined."
      [528:2]: "Variables that are not initially defined are initially
      undefined."

      Question: Is d1 initially undefined?

Answer: I don?t care.
Extended answer: Just look at 19.6.1 and forget about the convoluted (and
incomplete) stuff about ?initially defined/undefined?.? According to your
first quote, whether d1 is initially defined or not, it *clearly* is
defined at the beginning of program execution.

      module m
      type t1
      integer, pointer :: p => NULL()
      contains
      procedure, private :: t1Assign
      generic, public :: assignment(=) => t1Assign
      end type t1

      type t2
      type(t1) :: base
      end type t2

      contains
      subroutine t1Assign(this, src)
      implicit none
      class(t1), intent(inout) :: this !!! what if intent(out)
      class(t1), intent(in) :: src
      print *, associated(this%p) !!! AAA
      end subroutine

      subroutine copy(dest, src)
      class(*), pointer :: dest
      class(*), intent(in) :: src
      allocate(dest, source=src)
      end subroutine copy
      end module

      program main

      use m
      class(*), pointer :: aa
      type(t2) :: bb

      allocate(bb%base%p)
      call copy(aa, bb)

      end

      Question 1: Is "this" at line AAA defined?

      Question 2: if the answer of 1 is YES, then what should it print?
      It seems this%p is not nullified because the default initialization
      doesn't apply to unlimited polymorphic object (dest) nor to the
      intent(inout) (this). Doesn't it mean the call to associated is
      invalid?

      Question 3: if the answer to 1 is YES, if I change "this" in
      "t1Assign" to "INTENT(OUT)"(so the default initialization is applied
      to "this"), is the call to associated then legal, and it should print
      false?



Answer  1:  Question  is  meaningless since there is no execution path that
reaches that line.? Perhaps you need a quote from the standard here:
??????????????? ?On successful allocation, if allocate-object and
source-expr have the same rank the value of allocate-object becomes the
value provided?
??????????????? That  is,  ?dest?  gets  the  value  of  ?src?, without the
involvement of intrinsic or defined assignment.

Answer  2:  Question  is meaningless because whether ?this? is ?defined? or
not  has  literally  *NO  BEARING  WHATSOEVER  UNDER  ANY CIRCUMSTANCES* on
whether  it  is  valid  to  execute  ?ASSOCIATED(this%p)?,  because being a
pointer component, the association status and definition status of ?this%p?
do  not affect the definition status of ?this?.? Your very first quote from
the standard tells you this.

Answer  2:  Of  course  your  problem  is that apparently some processor is
invoking defined assignment when it is not allowed to.

Default initialisation would be invoked by
ALLOCATE(dest,MOLD=src)
but then you would need a SELECT TYPE to assign a value to dest, which is a
bit inconvenient.

Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.

_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.j3-2Dfortran.org_mailman_listinfo_j3&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=57cafTO2T1scnwZfrlLPsghkmjFH2AuUtlcWE5nRktg&m=DeGpp8VztgpvG-j8IBp7jtt3fE53vdktIcspy7zqygQ&s=AeiwMXFpjZ54_JAv3TXJpmCWeFJYt9SisA12pc5ROQs&e=



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171222/a9f31910/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171222/a9f31910/attachment.gif>



More information about the J3 mailing list