Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Pointer behavior in procedure

OP1
New Contributor III
607 Views

Consider the two following examples:

 

SUBROUTINE S1
IMPLICIT NONE
INTEGER, POINTER :: P(:)
ALLOCATE(P(10))
END SUBROUTINE S1
SUBROUTINE S2
IMPLICIT NONE
INTEGER, ALLOCATABLE :: TEMP(:)
INTEGER, POINTER :: P(:)
ALLOCATE(TEMP(10))
P => TEMP
END SUBROUTINE S2

 

Is it correct to say that S1 leads to a memory leak whereas S2 does not?

0 Kudos
2 Replies
IanH
Honored Contributor III
593 Views

Yes.

(The TARGET attribute needs to be added to TEMP in S2.)

0 Kudos
OP1
New Contributor III
586 Views

Ooops, yes I forgot TARGET (I didn't try to compile those two examples, hence the miss).

Thanks for confirming my understanding of this though! Very much appreciated.

0 Kudos
Reply