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 on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Pointer behavior in procedure

OP1
New Contributor III
747 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
733 Views

Yes.

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

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