function - Passing type bound procedures as arguments -


i trying pass type bound procedure argument subroutine. want know if possible in fortran. here code snippet shows trying .

module type_definitions   type test_type   integer :: i1, i2,i3  contains     procedure :: add_integers_up   end type test_type  contains     subroutine add_integers_up(this,i4,ans)        class(test_type) ::         integer :: i4,ans         ans = this%i1+this%i2+this%i3+i4     end subroutine add_integers_up  subroutine print_result_of_subroutine(i4,random_subroutine)    integer :: i4,ans     interface       subroutine  random_subroutine(i1,i2)         integer:: i1,i2      end subroutine random_subroutine   end interface    call random_subroutine(i4,ans)    write(*,*) ans    end subroutine print_result_of_subroutine   end module type_definitions   program main     use type_definitions    implicit none     integer :: i1,i2,i3,i4    integer :: ans     type(test_type) :: test_obj     i1 =1; i2=2; i3=3    test_obj%i1 = i1     test_obj%i2 = i2     test_obj%i3 = i3     i4 = 4     call print_result_of_subroutine(i4,test_obj%add_integers_up)       end program main 

is possible in fortran? compiler error when try compile code using ifort.

test_obj%add_integers_up not procedure - binding happens to procedure called add_integers_up. cannot pass binding actual argument.

if want pass specific procedure binding associated with, pass procedure! hypothetically:

call print_result_of_subroutine(i4, add_integers_up) 

but other posters have noted, in example code interface of procedure not match interface of corresponding dummy argument in print_result_of_subroutine.

if test_obj%add_integers_up referred associated procedure pointer component (and interface component matched being expected print_result_of_subroutine) things work appear expecting.

note fortran 90 not support type bound procedures (or procedure pointer components) - code requires fortran 2003.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -