Print

Print


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?

-- greg

MODULE deallocate_

CONTAINS

  INTEGER FUNCTION DEALLOC(V)
    INTEGER :: STATUS
    ! REAL, POINTER :: V works for everyone
    REAL, TARGET :: V
    REAL, POINTER :: VP
    VP => V
    DEALLOCATE (VP, STAT = STATUS)
    DEALLOC = STATUS
  END FUNCTION DEALLOC

END MODULE deallocate_

PROGRAM VECTORCLASS
 USE deallocate_
 IMPLICIT NONE
 REAL, POINTER :: VP
 INTEGER :: STATUS
 ALLOCATE( VP, STAT = STATUS)
 WRITE( *, *) '  Allocate STATUS = ', STATUS
 STATUS = DEALLOC (VP)
 WRITE( *, *) 'Deallocate STATUS = ', STATUS
END