Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:21:58+00:00 2026-06-08T03:21:58+00:00

I am trying to pass a type bound procedure as an argument to another

  • 0

I am trying to pass a type bound procedure as an argument to another subroutine. I want to know if this is possible in Fortran. Here is a code snippet that shows what I am trying to do .

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) :: this 
       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 this possible to do in Fortran? I get a compiler error when I try to compile this code using ifort.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:22:00+00:00Added an answer on June 8, 2026 at 3:22 am

    test_obj%add_integers_up is not a procedure – it is a binding that happens to be to a procedure called add_integers_up. You cannot pass a binding as an actual argument.

    If you want to pass the specific procedure that the binding is associated with, then pass the procedure! Hypothetically:

    call print_result_of_subroutine(i4, add_integers_up)
    

    But as other posters have noted, in your example code the interface of that procedure does not match the interface of the corresponding dummy argument in print_result_of_subroutine.

    If test_obj%add_integers_up referred to an associated procedure pointer component (and the interface for that component matched what was being expected by the print_result_of_subroutine) then things would work as you appear to be expecting.

    Note that Fortran 90 does not support type bound procedures (or procedure pointer components) – your code very much requires Fortran 2003.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In VB6, I'm trying to pass a late bound object to another form. frmMain.vb
I am trying to pass a long long type as an argument to a
I am trying to pass an array of type Coordinates (coordinate[] arrCoordinates) to another
I'm trying to pass an object of type Team to another Activity in my
Trying to pass a string argument to a function, which will then be used
I am trying to pass an argument asins to each form in a modelformset,
I'm trying to pass a form field of type file to a CFFUNCTION. The
I am trying to pass a list object of type List<UploadQueue> to a WCF
I'm trying to pass an array like this using jQuery, but the PHP script
I'm trying to pass parameter of short type to C++ unmanaged function imported from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.