Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

F-95 constraints on using pointers inside pure procedures

forall
Beginner
519 Views
The following (highly trimmed) code works on CVF/IVF but does not compile on some other compilers, which claim that it violates the F-95 standard. So I'd like to check if indeed this code violates the F-95 standard.

!=============
module m
implicit none
type parrType
integer,pointer::v(:)=>null()
endtype parrType
contains
!--
pure subroutine parrN(a,i0,i1,s,b)
implicit none
type(parrType),intent(in)::a(:)
integer,intent(in)::i0,i1
integer,intent(out)::s,b
s=size(a)
b=minval(a(1)%v(i0:i1))
endsubroutine parrN
!--
endmodule m
!=============


the error message applying to both executable statements (ie, 2 separate errors) was:
"a" must not be modified or used as a pointer target inside of a pure subprogram, because it is in common, a dummy argument, host associated, or use associated. >>

I wonder whether F-95 guarantees that intrinsics such as size and minval are pure and do not affect pointer arguments in the context of using them inside pure procedures. As far as I can see there can be no possible side effects with the code above...
thanks,
dmitri
0 Kudos
1 Reply
Steven_L_Intel1
Employee
519 Views
The standard says:

"All intrinsic functions defined in this standard are pure."

I can't find any wording in the standard that would support calling this code non-conforming. It could be that the other compilers are misinterpreting the following constraint:

Constraint: In a pure subprogram any variable which is in common or accessed by host or use
association, is a dummy argument to a pure function, is a dummy argument with
INTENT (IN) to a pure subroutine, or an object that is storage associated with any
such variable, shall not be used in the following contexts:
...
(8) As the expr of an assignment-stmt in which the variable is of a derived type if the derived
type has a pointer component at any level of component selection;


but that requires that the variable on the left side be the one of derived type with a pointer component, which is not the case here.

I suggest asking the other vendor(s) what their rationale is for this diagnostic.
0 Kudos
Reply