Silverfrost Forums

Welcome to our forums

Allocatable Vs Pointer

5 Aug 2014 7:12 #14403

Hello Whether 'Allocatable' and 'Pointer' can be mutually used. I understand Pointer denotes to the memory address only, but Allocatable allocates the physical memory to contain the values. WIth pointer definition, where the contents (user_defined values) goes.

I also noticed that there no difference between these two under the following situation. In

Module M1

contains
subroutine passtoSub(s)
real, pointer :: s(:)

s(1) = 10.0
!assign values here
end subroutine passtoSub

end module 

program main
use M1
real , allocatable,save :: myarray(:)

allocate myarray(10)

call passtoSub(myarray)

print*, (myarray(I),I=1,ubound(myarray,1))

end program main

This works fine, but how the datas of myarray in Main and Subroutine handled as this code serves the purpose. Just want to understand more on this.

5 Aug 2014 9:04 #14404

In addition, are they use the same memory locations and addresses in both cases? Like Main allocates a different memory while pass it on to Subroutine, Subroutine pointer takes a different memory but the lifespan of the pointer only at Subroutine level, once control comes back to Main, it released?

Appreciate for clarifications..

Thank you

Please login to reply.