- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need some help in understanding the following:
Assigning a pointer to a subroutine and looking at the address of the "pointee" in the debuggers watch list gives "a value" in the main program. While passing this pointee to another subroutine and assigning another pointer to this address shows a "different value" for its address. However when using this pointer to call the orginal subroutine the call is successful.
Here's an example ...
!***********************************
!***********************************
program PointerTest
implicit none
external ASub, BSub
integer :: BSubPtr
pointer (p, BSubPtr)
p = loc(BSub)
!Here loc(BSubPtr) == loc(BSub)
call ASub(BSubPtr)
end program
!***********************************
!***********************************
subroutine ASub(OldSubPtr)
integer :: OldSubPtr, NewSubPtr
pointer(p, NewSubPtr)
p = loc(OldSubPtr)
!Here loc(OldSubPtr) == loc(BSub) /= loc(NewSubPtr) Why?
call NewSubPtr()
!Note the call to BSub through NewSubPtr is successfull
!However, it seems like they should have the same
!address/location.
end subroutine
!***********************************
!***********************************
subroutine BSub()
end subroutine
!***********************************
!***********************************
Thanks for any help.
Assigning a pointer to a subroutine and looking at the address of the "pointee" in the debuggers watch list gives "a value" in the main program. While passing this pointee to another subroutine and assigning another pointer to this address shows a "different value" for its address. However when using this pointer to call the orginal subroutine the call is successful.
Here's an example ...
!***********************************
!***********************************
program PointerTest
implicit none
external ASub, BSub
integer :: BSubPtr
pointer (p, BSubPtr)
p = loc(BSub)
!Here loc(BSubPtr) == loc(BSub)
call ASub(BSubPtr)
end program
!***********************************
!***********************************
subroutine ASub(OldSubPtr)
integer :: OldSubPtr, NewSubPtr
pointer(p, NewSubPtr)
p = loc(OldSubPtr)
!Here loc(OldSubPtr) == loc(BSub) /= loc(NewSubPtr) Why?
call NewSubPtr()
!Note the call to BSub through NewSubPtr is successfull
!However, it seems like they should have the same
!address/location.
end subroutine
!***********************************
!***********************************
subroutine BSub()
end subroutine
!***********************************
!***********************************
Thanks for any help.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Which compiler and version are you using?
The program you post here is not legal becasuse NewSubPtr needs to be declared EXTERNAL in Asub in order to call it. (That's the requirement we put on using an integer pointer to a routine.)
If I add the EXTERNAL declaration, then CVF 6.6C does what you describe - I'm not sure why. Intel Visual Fortran won't link the program - that's a bug I'll report.
The program you post here is not legal becasuse NewSubPtr needs to be declared EXTERNAL in Asub in order to call it. (That's the requirement we put on using an integer pointer to a routine.)
If I add the EXTERNAL declaration, then CVF 6.6C does what you describe - I'm not sure why. Intel Visual Fortran won't link the program - that's a bug I'll report.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the response.
I'm using CVF Professional 6.5.0.
One other question.
Why can I access "BSub" through through "NewSubPtr" when its address is different than "BSub". Does it really point to the correct address and for some reason "loc(NewSubPtr)" returns the wrong address.
Thanks again.
I'm using CVF Professional 6.5.0.
One other question.
Why can I access "BSub" through through "NewSubPtr" when its address is different than "BSub". Does it really point to the correct address and for some reason "loc(NewSubPtr)" returns the wrong address.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I believe it's just the loc that is misbehaving. loc() requires a lot of special-case code in the compiler and has been a source of trouble in the past.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page