- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
integer::locj
integer, pointer:: pj
locj=loc(j)
if(locj==loc(pj))then
...
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The standard way to check whether pj points to j is:
if (ASSOCIATED(pj, j))
however, the method with LOC() you described should work as well.
I don't see the essential difference between the pictures you attached. You cannot expect the addresses to be the same; they can be pretty much anything. Is there something that I'm missing?
You probably know that a pointer has to be explicitly initialized before you try to query ASSOCIATED or LOC,like any other variable, don't you? (Otherwise, you'll get random result):
integer, pointer:: p
if (associated(p)) then
write (*,*) loc(p)
end if
Write line will get executed randomly, depending on compiler, environment, and phase of the Moon, as it has "undefined" association status. p must be explicitly NULLIFYed orassociated with somethingbefore you do anything with it.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much!
Of course I know the adresses are not the same, the difference is: in CVF, when the cycle ended, the value ofI is 3 but in IVF the value of I is 4 (see the watch window below). That means in CVF I can find a pointer which points to some target, but in IVF I can't find!
Sincerely,
Zhanghong Tang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You mean loc(pj)=loc(j) is equivalent withpj is associated to j?
But I think there are still difference between IVF and CVF's compilers (I dare not say IVF's compiler has bug).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You mean loc(pj)=loc(j) is equivalent withpj is associated to j?
Yes. Actually, it's equivalent to:
program Assoc
integer, target:: j
integer, pointer:: pj
logical:: b
pj=>j
b = loc(pj).eq.loc(j) .and. loc(pj).ne.0
b = associated(pj, j)
end program Assoc
Assembly output of the two lines is identical:
9: b = loc(pj).eq.loc(j) .and. loc(pj).ne.0
00401029 lea edx,[J (004462f4)]
0040102F mov ecx,dword ptr [PJ (004462e8)]
00401035 xor eax,eax
00401037 cmp ecx,edx
00401039 sete al
0040103C mov edx,dword ptr [PJ (004462e8)]
00401042 xor ecx,ecx
00401044 cmp edx,0
00401047 setne cl
0040104A and ecx,eax
0040104C neg ecx
0040104E mov dword ptr [B (004462f0)],ecx
10: b = associated(pj, j)
00401054 lea edx,[J (004462f4)]
0040105A mov eax,dword ptr [PJ (004462e8)]
00401060 xor ecx,ecx
00401062 cmp eax,edx
00401064 sete cl
00401067 mov eax,dword ptr [PJ (004462e8)]
0040106D xor edx,edx
0040106F cmp eax,0
00401074 setne dl
00401077 and edx,ecx
00401079 neg edx
0040107B mov dword ptr [B (004462f0)],edx
(I dare not say IVF's compiler has bug).
Neither do I :-), but we both witnessed it isn't quite bug free.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am fool. When I want to know the address of a pointer, I always type
loci=loc(ip)
Now I have a simple way:)
Thanks!
For your answer, I think it maybe right in this code, but when I replace
loc(pj)==loc(j)
with
associated(pj, j)
the program ran error.
Of course in my code pj and j is more complicated than a simple integer pointer.
Maybe I have done something wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page