(j3.2006) deallocating pointer function results
Robert Corbett
robert.corbett
Tue Nov 3 19:15:36 EST 2015
On 11/03/15 13:44, Van Snyder wrote:
> On Tue, 2015-11-03 at 02:34 -0800, Robert Corbett wrote:
>> > The following message is based on a thread on comp.lang.fortran.
>> > All references are with respect to Fortran 2008.
>> >
>> > Consider the following program:
>> >
>> > !-----------------------------------------------------------------
>> >
>> > program main
>> >
>> > deallocate( new_int() ) ! (1)
>> > call my_deallocate( new_int() ) ! (2)
>> > call hmm_deallocate( new_int() ) ! (3)
>> >
>> > contains
>> > function new_int()
>> > integer, pointer :: new_int
>> > allocate(new_int)
>> > new_int = 3
>> > end function
>> >
>> > subroutine my_deallocate(p)
>> > integer, pointer :: p
>> > deallocate( p )
>> > end subroutine
>> >
>> > subroutine hmm_deallocate(p)
>> > integer, pointer :: p, q
>> > q => p
>> > deallocate( q )
>> > end subroutine
>> > end
>> >
>> > !-----------------------------------------------------------------
>> > The statement marked (2) leads to prohibited behavior.
>> > Subclause 5.3.10, paragraph 5, states
>> >
>> > If no INTENT attribute is specified for a dummy argument,
>> > its use is subject to the limitations of its effective
>> > argument (12.5.2).
>> >
>> > Because a function reference is not allowed as an
>> > /allocate-object/ in a DEALLOCATE statement, a dummy argument
>> > corresponding to an actual argument that is a function reference
>> deallocate statement. Argument association is not textual substitution.
The quoted restriction is the restriction that prohibits changing the
value of a dummy variable that is associated with an actual argument
that is not a variable. The program
PROGRAM MAIN
CALL SUBR(FUNC())
CONTAINS
FUNCTION FUNC()
FUNC = 1.0
END FUNCTION
SUBROUTINE SUBR(X)
X = 2.0
PRINT *, X
END SUBROUTINE
END
is not standard conforming because it violates that restriction. The
program that deallocates the pointer dummy variable violates the same
restriction, but for a pointer dummy variable instead of an ordinary
dummy variable.
Robert Corbett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20151103/88aa659a/attachment.html
More information about the J3
mailing list