Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

Pointer behavior in procedure

OP1
New Contributor III
791 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
777 Views

Yes.

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

0 Kudos
OP1
New Contributor III
770 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