(j3.2006) Unlimited poly and pointer component

Daniel C Chen cdchen
Mon Dec 18 16:42:06 EST 2017



Hello,

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?

Case 2:

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?

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171218/9296b4ad/attachment.html>



More information about the J3 mailing list