Passing a generic procedure to a function as actual argument

后端 未结 2 397
死守一世寂寞
死守一世寂寞 2021-01-12 07:25

I am attempting to pass a generic procedure as an actual argument to a function:

module mymod
implicit none

interface func
  module procedure :: func1
  mod         


        
2条回答
  •  星月不相逢
    2021-01-12 07:35

    No, this is not allowed. Actually, you cannot even pass generic INTRINSIC functions as dummy arguments.

    A standard compliant way is to use the right specific functions directly. With INTRINSIC functions you sometimes must write a wrapper for the right kind, when the specific doesn't have a standard name.

    For example:

      call integrate(derf,0.,1.)
    
      contains
        function derf(x)
          real(dbl) :: derf
          real(dbl), intent(in) :: x
          derf = erf(x)
        end function
      end
    

    is necessary if you want to pass the double precision real (or any other) version of erf() because there is no specific function available.

提交回复
热议问题