View Full Version : FORTRAN: Allocating a pointer
Hi all.
When I have the following code in FORTRAN:
integer, pointer :: ptr
ALLOCATE(ptr)
then does "ptr" recieve a new address (i.e. do we have "ptr => <new integer>") or does the pointer retain its address (i.e. we don't have "ptr => ...")?
silverfrost
Oct23-09, 08:12 PM
That is a bit weird just allocating a single integer. If you did this:
integer, pointer :: ptr(:)
allocate(ptr(20))
Then an array of 20 integers would be allocated and ptr would be set to point to the new array. If ptr already points to an array then that array will not automatically be deallocated.
HallsofIvy
Oct24-09, 02:28 PM
Hi all.
When I have the following code in FORTRAN:
integer, pointer :: ptr
ALLOCATE(ptr)
then does "ptr" recieve a new address (i.e. do we have "ptr => <new integer>") or does the pointer retain its address (i.e. we don't have "ptr => ...")?
What do you mean a "new" address? When you declare the pointer, there is NO memory location assigned to it until memory is allocated to it.
vBulletin® v3.7.6, Copyright ©2000-2009, Jelsoft Enterprises Ltd.