[J3] surprisingly PURE
Van Snyder
van.snyder at jpl.nasa.gov
Wed Apr 22 02:13:13 EDT 2020
Pointers allow one to do things with pure procedures that one might
think violate the "principle" of PURE.
One can pass an object of a type that has a pointer component, with the
component associated with a variable that's not mentioned in the
argument list, and then the procedure can assign a valueto that
variable (or undefine it).
real, target :: X = 1.0
type :: T
real, pointer :: X
end type T
type(t) :: V
print *, 'Before call, X =', x
v%x => x
call s ( v )
print *, 'Afer call, X =', x
contains
subroutine S ( A )
type(t), intent(inout) :: A
a%x = 42.0
end subroutine S
end
This has been with us since the beginning of PURE, but some might say
"that's not pure!"
Is this really different from changing X by way of a pointer component
with default initialization that associates it with X?
Bob's example is a bit diffent because it doesn't involve a side effect
using a dummy argument that some might argue violates the spirit of
"pure."
But, taking these together, and the potential problems with
polymorphism that appear not to be addressable with constraints, is
there really anything the standard can do to plug every loophole?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20200421/f0c36dfb/attachment.htm>
More information about the J3
mailing list