deallocating via pointer associated with allocatable array
From: Bart Vandewoestyne (MyFirstName.MyLastName_at_telenet.be)
Date: 03/23/05
- Next message: Richard E Maine: "Re: deallocating via pointer associated with allocatable array"
- Previous message: Richard E Maine: "Re: xlf Fortran Oddity"
- Next in thread: Richard E Maine: "Re: deallocating via pointer associated with allocatable array"
- Reply: Richard E Maine: "Re: deallocating via pointer associated with allocatable array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Mar 2005 16:26:30 +0000 (UTC)
Section 6.5.3 in Fortran 95/2003 explained:
"Its general form is
deallocate(allocate-object-list [,stat=stat])
where each allocate-object is an allocatable array that is allocated or
a pointer that is associated with the whole of a target that was
allocated through a pointer in an allocate statement \footnote{Note that
this excludes a pointer that is associated with an allocatable array}"
Does this mean the deallocate statement at the end of the following program
falls under this exception in the footnote and should therefore give compiler
errors/warnings or runtime errors or something alike?
program test_deallocate
implicit none
! The allocatable array we are gonna point to
integer, dimension(:), allocatable, target :: the_target
! The pointer that is gonna point to our allocatable array
integer, dimension(:), pointer :: p
! Allocate memory for our allocatable array
allocate(the_target(10))
! Now associate the pointer with this allocatable array
p => the_target
! Deallocating through the pointer seems to work... ???
deallocate(p)
end program test_deallocate
I am asking this because somewhere in my bigger code i had something like:
real(kind=dp), dimension(:), allocatable, target :: temp
and in the code i had a pointer pointing to this allocatable, and then I tried
to deallocate the memory through a deallocate of the pointer. When i ran my
code, i got:
Pointer in DEALLOCATE is ASSOCIATED with an ALLOCATABLE array
Program terminated by fatal error
Aborted
Changing the declaration of temp into:
real(kind=dp), dimension(:), pointer :: temp
solves my problem, but of course I wanted to understand exactly why, and i
tried to write a simple testcase which suffers from the same error
(see the above program), but apparently there still must be something
wrong as when I try to run my testprogram i cannot reproduce the error as above.
I don't see what is wrong with my simple testcase, since i am trying to
deallocate through a pointer which is associated with an allocatable array,
isn't it? Then why don't i get the same runtime error as cited above?
Regards,
Bart
PS: I am compiling with
Fortran Company/NAG F compiler Release 20020224
-- "Share what you know. Learn what you don't."
- Next message: Richard E Maine: "Re: deallocating via pointer associated with allocatable array"
- Previous message: Richard E Maine: "Re: xlf Fortran Oddity"
- Next in thread: Richard E Maine: "Re: deallocating via pointer associated with allocatable array"
- Reply: Richard E Maine: "Re: deallocating via pointer associated with allocatable array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|