- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I do not know whether a target will be deallocated if a pointer,which point to the target, is deallocated.I wrote a small program shows below and compiled it with Intel Fortran 7.1 and CVF 6.1. The results are different. Which result is correct?
1.)Intel Fortran 7.1
List...
a= 10
b= 10
c= 10
List...
a= 10
b is not associated.
c= 10
List...
a is not associated.
b is not associated.
c= 10
2.)CVF 6.1
List...
a= 10
b= 10
c= 10
List...
a= 3410140
b is not associated.
c= 3410140
forrtl: severe (157): Program Exception - access violation
The program:
program test
implicit none
INTEGER,pointer::a,b,c
ALLOCATE(a)
a=10
b=>a
c=>b
call List(a,b,c)
DEALLOCATE(b)
call List(a,b,c)
DEALLOCATE(a)
call List(a,b,c)
contains
subroutine List(a,b,c)
implicit none
INTEGER,POINTER::a,b,c
PRINT*,"List..."
IF(ASSOCIATED(a))then
PRINT*,"a=",a
else
PRINT*,"a is not associated."
END if
IF(ASSOCIATED(b))then
PRINT*,"b=",b
else
PRINT*,"b is not associated."
END if
IF(ASSOCIATED(c))then
PRINT*,"c=",c
else
PRINT*," is not associated."
END if
PRINT*,""
end subroutine
end program
I do not know whether a target will be deallocated if a pointer,which point to the target, is deallocated.I wrote a small program shows below and compiled it with Intel Fortran 7.1 and CVF 6.1. The results are different. Which result is correct?
1.)Intel Fortran 7.1
List...
a= 10
b= 10
c= 10
List...
a= 10
b is not associated.
c= 10
List...
a is not associated.
b is not associated.
c= 10
2.)CVF 6.1
List...
a= 10
b= 10
c= 10
List...
a= 3410140
b is not associated.
c= 3410140
forrtl: severe (157): Program Exception - access violation
The program:
program test
implicit none
INTEGER,pointer::a,b,c
ALLOCATE(a)
a=10
b=>a
c=>b
call List(a,b,c)
DEALLOCATE(b)
call List(a,b,c)
DEALLOCATE(a)
call List(a,b,c)
contains
subroutine List(a,b,c)
implicit none
INTEGER,POINTER::a,b,c
PRINT*,"List..."
IF(ASSOCIATED(a))then
PRINT*,"a=",a
else
PRINT*,"a is not associated."
END if
IF(ASSOCIATED(b))then
PRINT*,"b=",b
else
PRINT*,"b is not associated."
END if
IF(ASSOCIATED(c))then
PRINT*,"c=",c
else
PRINT*," is not associated."
END if
PRINT*,""
end subroutine
end program
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure -- you'd better check this out with folks from comp.lang.fortran -- but, based on similar situations in the Standard, I'd say that both are correct.
There are many situations where the Fortran Standard places the burden of responsibility to the programmer. One of these is not to query ASSOCIATED on a pointer whose status is undefined. For example:
There are many situations where the Fortran Standard places the burden of responsibility to the programmer. One of these is not to query ASSOCIATED on a pointer whose status is undefined. For example:
integer, pointer:: a !undefined status, a !is not initialized logical:: b b = associated(a) !illegal code -- but it's your fault!Oh, I found it in F2000 draft, and it's certainly just rewritten from F95 (F2000 16.4.2.1.3, page 416):
16.4.2.1.3 Events that cause the association status to become undefined
...
(2) The target of the pointer is deallocated other than through the pointer
So, the compiler is allowed to do as it's pleased with illegal code, such as yours. After B is deallocated, the only legal action with a and c is to NULLIFY them or re-associate them with something else, but you may not use ASSOCIATE on them. This is known as "phenomenon of dangling pointers".
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