Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.

Pointer behavior in procedure

OP1
New Contributor II
238 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
Black Belt
224 Views

Yes.

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

OP1
New Contributor II
217 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.

Reply