- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
We often use associated to judge if a pointer is null or not. But when the target of a pointer has been deallocated, the function associated can't work. Can anyone tell me how to judge it?
Thanks,
Zhanghong Tang
Anexample:
type(test), pointer:: test1, test2
allocate(test1)
test2=>test1
if(associated(test2))then
write(*,*)'associated'
else
write(*,*)'not associated'
endif
deallocate(test1)
! How to judge the target of test2 has been deallocated?????
if(associated(test2))then
write(*,*)'associated'
else
write(*,*)'not associated'
endif
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ican't use the following code:
if(associated(test2, tes1))then
...
Because in real work I don't know test2's target is test1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't. Quote from Fortran Standard (2003 draft, but it's the same in F95):
16.4.2.1.3 Events that cause the association status of pointers to become undefined
The association status of a pointer becomes undefined when
25(1) The pointer is pointer-assigned to a target that has an undefined association status,
(2) The target of the pointer is deallocated other than through the pointer
And Note 16.13:...the target will cease to exist, leaving the pointer "dangling". This standard considers such pointers to have an undefined association status. They are neither associated nor disassociated. They shall not be used again in the program until their status has been reestablished. There is no requirement on a processor to be able to detect when a pointer target ceases to exist.
I know it doesn't help much, but you will probably have to redesign the program so that it doesn't happen.
Jugoslav

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