----- Original Message -----
From: Herbert Fruchtl <[log in to unmask]>
To: Fortran List <[log in to unmask]>
Sent: 10 October 2000 10:31
Subject: Re: Allocation status of pointers
> > Is there a simple way to determine the association status of a pointer
> > variable, analogous to the intrinsic ALLOCATED function for non-pointer
> > arrays with the ALLOCATABLE attribute?
>
> ASSOCIATED. But note that the initial association status of a pointer is
> undefined, so you have to NULLIFY it first.
>
> HTH,
>
> Herbert
What did slightly concern me about ASSOCIATED was that there seemed no way
to distinguish between different forms of association. For example the
following simple program:
program association_test
implicit none
real, pointer, dimension(:) :: x
real, target, dimension(1:3) :: y=10.0
nullify (x)
allocate (x(10))
if (associated(x)) then
write (*,*) 'x associated after allocation'
end if
deallocate (x)
nullify (x)
x => y
write (*,*) 'y(1)=',y(1)
write (*,*) 'x(1)=',x(1)
write (*,*) 'y(2)=',y(2)
write (*,*) 'x(2)=',x(2)
write (*,*) 'y(3)=',y(3)
write (*,*) 'x(3)=',x(3)
if (associated(x)) then
write (*,*) 'x associated after pointing at y.'
end if
end program association_test
gives the ouput:
x associated after allocation
y(1)= 10.000000
x(1)= 10.000000
y(2)= 10.000000
x(2)= 10.000000
y(3)= 10.000000
x(3)= 10.000000
x associated after pointing at y.
Attempting to deallocate x after the second association gives a run-time
error in ftn90, and a programmer might conceivably want to check for this
form of association before carrying out deallocation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|