(j3.2006) (SC22WG5.5374) [ukfortran] Question on PURE subroutines

Malcolm Cohen malcolm
Thu Dec 4 20:29:22 EST 2014


Furthermore, you don't need a pointer to cause a global side-effect in a PURE 
subroutine, and all the proposed fixes do not even approach preventing 
side-effects in PURE subroutines (luckily, since that would make them completely 
useless).

Consider

Module junk
  Type t
    Real :: c
  End Type
  Type(t) x(10)
  Interface Assignment(=)
    Module Procedure ugh
  End Interface
Contains
  Pure Elemental Subroutine ugh(a,b)
    Type(t),Intent(InOut) :: a
    Integer,Intent(In) :: b
    a%c = a%c + x(3)%c + b
  End Subroutine
End Module
Program bad
  Use junk
  x%c = 1
  Forall (i=1:10) x(i) = 0
  Print *,x
End Program

If this is evaluated "in parallel", it might print 2 for all values.  If it is 
evaluated sequentially, it will print some 2's and some 3's.

This is not conforming merely because no interpretation is established.  It 
might behoove us to make this into a more explicit non-constraint requirement, 
e.g. something like
   "An invocation of a pure subroutine shall not cause a variable to become 
defined or undefined if that variable is referenced, directly or indirectly, by 
that pure subroutine."

I see no point whatsoever in playing with pointer restrictions - it's like 
closing the doors of a stable that doesn't even have any walls!

Cheers,
-- 
................................Malcolm Cohen, Nihon NAG, Tokyo. 




More information about the J3 mailing list