Print

Print


first of all thanks to everyone that replied.
the results were quite interesting.

a closer examination of the associated function 
does show that the pointer must not be undefined.

and as John Reid states there is no requirement on the processor
to check this.

so all compilers were standard conforming and the results
varied due to the different memory requirements
of the two programs.

On Mon, 27 Mar 2000 10:32:14 +0100 (BST) John Reid 
<[log in to unmask]> wrote:

> > Jane Sleightholme and I have been looking at simple
> > examples to illustrate dangling pointers and memory 
> > leaks.
> > 
> > PROGRAM C20_04
> > IMPLICIT NONE
> > REAL , POINTER :: P2=>null()
> > 
> > interface
> >   subroutine test(p2)
> >   implicit none
> >   REAL , POINTER :: P2
> >   end subroutine test
> > end interface 
> > 
> >   print *,' staring main program'
> >   
> >   if (associated(p2)) then
> >     print *,' p2 is associated '
> >   end if
> > 
> >   call test(p2)
> > 
> >   if (associated(p2)) then
> >     print *,' p2 is associated '
> >   end if
> > 
> >   print *,' p2  in main program = ',p2
> > 
> >   print *,' returning from test routine'
> > 
> > end program c20_04
> > 
> > subroutine test(p2)
> > implicit none
> > REAL , POINTER :: P1 
> > REAL , POINTER :: P2
> > integer :: istat
> > integer :: t
> >   print *,' entering test' 
> >   allocate(p1)
> >   P1=21.0
> > 
> > ! The value 21.0 is now stored in the 
> > ! memory location that P1 points to.
> > 
> >   P2=>P1
> > 
> > ! verify that they are the same
> > 
> >   PRINT * , ' p1 = ',P1
> >   PRINT * , ' p2 = ',P2
> >   p2=p1+1
> > 
> > ! verify that they are both the same
> > 
> >   PRINT * , ' p1 = ',P1
> >   PRINT * , ' p2 = ',P2
> > 
> > ! Now release the memory.
> > ! P1 becomes disassociated.
> > 
> >   deallocate(p1,stat=istat)
> 
> At this point, the pointer association status of p2 becomes undefined.
> This means that from here on, you should make no further reference to
> it until the pointer association status is defined by a pointer
> association, allocation, or nullification.  There is no requirement on
> the processor to check this.
>  
> Hope this helps,
> 
> John Reid. 

-------------------
Ian Chivers
[log in to unmask]

* This e-mail message was sent with Execmail V5.0 *



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%