×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

simple pointer problem

simple pointer problem

simple pointer problem

(OP)
Dears,

I have a strange problem which I do not understand what is it.
Based on pointers definition the simple code which I wrote below should work, but it does not please help me.

CODE --> FORTRAN

module all
contains
subroutine deall(a)
  integer, pointer :: a
  integer, pointer :: curr => null()
  curr => a
  if (associated(curr)) then
     deallocate(curr)
     nullify(curr)
  endif
end subroutine deall
end module

program test
  use all
  implicit none
  integer, pointer :: a=>null()
  integer, pointer :: b=>null()
  allocate(a)
  a=10
  print*,associated(a)
  call deall(a)
  print*,associated(a)
End Program test 

the subroutine can not deallocate the pointer which according to text book should be the case
please help me in this regard.

cheers,

RE: simple pointer problem

You've got what is known in Computer Science as a dangling reference. Basically whatever a was pointing to has been deallocated but a doesn't know about it. That is why languages like C# and Java have introduced reference counting: it is to avoid such problems (but you're not out of the woods - there are other problems)

CODE

subroutine deall(curr)
  integer, pointer :: curr
  integer, pointer :: dangling
  dangling => curr
  if (associated(curr)) then
     deallocate(curr)
     nullify(curr)
  endif
  print *, 'current  is ', associated(curr)
  print *, 'dangling is ', associated(dangling)
end subroutine deall 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close