Greg Lindahl said:
> Our compiler checks at run-time to make sure a pointer in a DEALLOCATE
> call points to something allocated by ALLOCATE. In the following
> program, we throw a run-time error and other compilers don't. I'm
> asserting that since V in the function DEALLOC is a REAL, the
> information that it is actually allocated is lost. Am I correct?
I don't think so.
See 04-007 [270:5-12].
This paragraph is perhaps not as easy to understand as it should be but
(1) pointers to the actual argument [on entry] now point to the dummy
and
(2) on exit, pointers to the dummy *remain* pointing to the actual
which indicates that VP in your example is associated with something that
was ALLOCATEd via ALLOCATE, to wit, the actual argument.
Certainly, the following modified version of your program is required to
work (i.e. print 0, assuming ALLOCATE/DEALLOCATE work at all!), by the
referenced paragraph in the standard:
MODULE deallocate_2
REAL,POINTER :: vp
CONTAINS
SUBROUTINE dealloc_part_1(v)
REAL,TARGET :: v
vp => v
END SUBROUTINE
INTEGER FUNCTION dealloc_part_2() RESULT(status)
DEALLOCATE(vp,STAT=status)
END FUNCTION
END
USE deallocate_2
REAL,POINTER :: vx
ALLOCATE(vx)
CALL dealloc_part_1(vx)
PRINT *,dealloc_part_2()
END
Cheers,
--
...........................Malcolm Cohen, Nihon NAG, Tokyo, Japan.
([log in to unmask])
|