|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
narayanamoorthy_k
Joined: 19 Jun 2014 Posts: 142 Location: Chennai, IN
|
Posted: Tue Aug 05, 2014 8:12 am Post subject: Allocatable Vs Pointer |
|
|
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
Code: |
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. _________________ Thanks and Regards
Moorthy |
|
Back to top |
|
|
narayanamoorthy_k
Joined: 19 Jun 2014 Posts: 142 Location: Chennai, IN
|
Posted: Tue Aug 05, 2014 10:04 am Post subject: |
|
|
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 _________________ Thanks and Regards
Moorthy |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|