I had the same problem and I didnβt even understand that it was a problem until I compiled gfortran. Unfortunately, it is also forbidden to have bogus procedure arguments for elementary procedures. However, it is still possible to achieve the desired functionality, although it is a bit ragged.
What you can legally do is call an elementary function a pure function. Depending on your needs, an elemental function can be type-bound or not.
Option 1
Place the pointer and the procedure function inside the module:
module A implicit none procedure(func_IF), pointer :: ptr => null() abstract interface pure function func_IF(x) real, intent(in) :: x real :: func_IF end function end interface contains ! Non type bound elemental elemental function myfun1(x) result(r) real, intent(in) :: x real :: r if(associated(ptr)) r = ptr(x) end function end module
Second option
Place both pointers and functions inside the derived type:
module B implicit none type :: foo procedure(func_IF), nopass, pointer :: ptr => null() contains procedure, pass :: myfun2 end type abstract interface pure function func_IF(x) real, intent(in) :: x real :: func_IF end function end interface contains ! Type bound elemental elemental function myfun2(this, x) result(r) class(foo), intent(in) :: this real, intent(in) :: x real :: r if(associated(this%ptr)) r = this%ptr(x) end function end module
A small test program:
program main use A use B implicit none type(foo) :: myfoo myfoo%ptr => bar ptr => bar print*, myfun1([10., 20.]) print*, myfoo%myfun2([10., 20.]) contains ! Demo pure function with interface func_IF pure function bar(x) real, intent(in) :: x real :: bar bar = x**2 end function end
sigma source share