fortran - Passing a generic procedure to a function as actual argument -


i attempting pass generic procedure actual argument function:

module mymod implicit none  interface func   module procedure :: func1   module procedure :: func2 endinterface func  contains  real function func1(x)   real,intent(in) :: x   func1 = 2*x endfunction func1  real function func2(x,y)   real,intent(in) :: x   real,intent(in) :: y   func2 = 2*x + 3*y endfunction func2  real function func3(func,x,y)   interface     real function func(x,y)       real,intent(in) :: x       real,intent(in) :: y     endfunction func   endinterface   real,intent(in) :: x   real,intent(in) :: y   func3 = func(x,y) endfunction func3  endmodule mymod  program myprogram use mymod implicit none write(*,*)func3(func,2.,3.) endprogram myprogram 

gfortran 6.2.0 notes cannot this:

test.f90:43:16:   write(*,*)func3(func,2.,3.)                 1 error: generic procedure ‘func’ not allowed actual argument @ (1) 

similarly, ifort 17:

test.f90(39): error #8164: generic interface name shall not used actual argument.   [func] write(*,*)func3(func,2.,3.) ----------------^ test.f90(39): error #6637: when dummy argument function, corresponding actual argument must function.   [func] write(*,*)func3(func,2.,3.) ----------------^ compilation aborted test.f90 (code 1) 

i reading through 2008 standard section on generic interfaces , cannot find such restriction. cannot think of reason why compiler not able resolve generic interface @ compile-time. gut telling me should doable, may not have right approach. know of standard-compliant way this?

no, not allowed. actually, cannot pass generic intrinsic functions dummy arguments.

a standard compliant way use right specific functions directly. intrinsic functions must write wrapper right kind, when specific doesn't have 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 want pass double precision real (or other) version of erf() because there no specific function available.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -