Pointer as a dummy argument

I am somewhat puzzled by the following program

module test
   implicit none

   type TestType
      integer :: i
   end type

contains
   subroutine foo(test)
      type (TestType), intent(out) :: test
      test%i = 5 
   end subroutine

   subroutine bar(test)
      type (TestType), intent(out) :: test
      test%i = 6 
   end subroutine

end module

program hello
   use test
   type(TestType) :: t

   call foo(t)
   print *, t%i 
   call bar(t)
   print *, t%i 
end program hello

and its derivatives. More on this later. As you know, Fortran passes ordinary arguments as a reference by reference, which means that the entity that appears in the dummy argument testfor fooand barrepresents the same memory space that is provided on the stack in program hello. So far so good.

Suppose I define in program hello type(TestType) :: tas a pointer and select it.

program hello
   use test
   type(TestType), pointer :: t

   allocate(t)

   call foo(t)
   print *, t%i
   call bar(t)
   print *, t%i

   deallocate(t)
end program hello

The code still works, with the only difference being that the object was not allocated on the stack, but on the heap.

Now suppose we go back to the selected stack of the program, and this line of the subprogram is defined as

 subroutine bar(test)
    type (TestType), pointer :: test
    test%i = 6 
 end subroutine

, , , , , , , . , pointer, , .

... ?

+2
1

comp.lang.fortran, :

,

()      type (TestType), :: test      % = 6   end

, , ,

: ALLOCATABLE POINTER. , () , , , . , ALLOCATABLE ; , . [ ] , ( OpenMP RECURSIVE). , "" " ", .

, , , .

. Fortran 2008 non-POINTER, TARGET, , INTENT (IN). ( ; , , , .)

... ?

, POINTER, -, .. Fortran 95 ALLOCATABLE dummy , , () .

, ALLOCATABLEs, POINTERs - , . , , , . (, , Fortran 2008. *)

*I mean:
   type t
       type(t), allocatable :: next
   end type

, ; F2008 , allocatables.

.

, Fortran ,

, , , . , , , , . , , . .

, . , , .

, , , , . .

, . , .

, .

+4

All Articles