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

  • Home
  • SEARCH
  • 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 808607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:35:18+00:00 2026-05-15T00:35:18+00:00

Is it possible to pass fortran 77 function as a callback function pointer to

  • 0

Is it possible to pass fortran 77 function as a callback function pointer to C/C++?
if so, how?

information I found on the web relates to fortran 90 and above, but my legacy code base is in 77.

many thanks

  • 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-05-15T00:35:19+00:00Added an answer on May 15, 2026 at 12:35 am

    If it can be done in FORTRAN 77, it will be compiler and platform specific. The new ISO C Binding of Fortran 2003 provides a standard way of mixing Fortran and C, and any language that follows or can follow the calling conventions of C, such as C++. While formally a part of Fortran 2003, and while there are extremely few Fortran compilers that fully support the entirety of Fortran 2003, the ISO C Binding is supported by numerous Fortran 95 compilers, including gfortran, g95, Sun, ifort, etc. So I recommend using one of these Fortran 95 compilers and the ISO C Binding method rather than figuring out some method for a particular method. Since FORTRAN 77 is a subset of of Fortran 95, why not compile your legacy code with one of these compilers, using Fortran 95 to add this new feature?

    I have called Fortran procedures from C using the ISO C Binding, but haven’t passed them as pointers. It should be possible. The steps are:

    1) you declare the Fortran function with the Bind(C) attribute,

    2) you declare all of the arguments using special types, such as integer(c_int), that match the types of C.

    Steps 1 & 2 make the Fortran function interoperable with C.

    3) You obtain a C-pointer to this Fortran function with the Fortran instrinsic function “c_funloc”, assigning the pointer value to a pointer of type “c_funptr”.

    4) In the Fortran code, you declare the C routine that you want to pass the function pointer to with an Interface, declaring it in in Fortran terms, but using the Bind(C) attribute and interoperable types so that the Fortran compiler knows to use the C-calling convention — making the C routine interoperable with Fortran.

    Then when you call the C-routine in the Fortran code, you can pass it the function pointer created in step 3.

    UPDATE: Code example: The Fortran main program “test_func_pointer” passes a pointer to the Fortran function “my_poly” to the C routine “C_Func_using_Func_ptr” and receives the result back from that C function.

    module func_pointer_mod
    
       use, intrinsic :: iso_c_binding
    
       implicit none
    
       interface C_func_interface
    
          function C_Func_using_Func_ptr ( x, Func_ptr ) bind (C, name="C_Func_using_Func_ptr")
    
             import
    
             real (c_float) :: C_Func_using_Func_ptr
             real (c_float), VALUE, intent (in) :: x
             type (c_funptr), VALUE, intent (in) :: Func_ptr
    
          end function C_Func_using_Func_ptr
    
       end interface C_func_interface
    
    
    contains
    
       function my_poly (x) bind (C, name="my_poly")
    
          real (c_float) :: my_poly
          real (c_float), VALUE, intent (in) :: x
    
          my_poly = 2.0 * x**2 + 3.0 * x + 5.0
    
          return
    
       end function my_poly
    
    end module func_pointer_mod
    
    
    program test_func_pointer
    
       use, intrinsic :: iso_c_binding
    
       use func_pointer_mod
    
       implicit none
    
       type (c_funptr) :: C_func_ptr
    
       C_func_ptr = c_funloc ( my_poly )
    
       write (*, *) C_Func_using_Func_ptr ( 2.5_c_float, C_func_ptr )
    
       stop
    
    end program test_func_pointer
    

    and

    float C_Func_using_Func_ptr (
    
       float x,
       float (*Func_ptr) (float y)
    
    ) {
    
       return ( (*Func_ptr) (x) );
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got it working by: Removing "float:left" on your "tabs"… May 15, 2026 at 7:55 pm
  • Editorial Team
    Editorial Team added an answer Assume the string's length is always an even number, >>>… May 15, 2026 at 7:55 pm
  • Editorial Team
    Editorial Team added an answer Update This answer was written ten year ago in 2010.… May 15, 2026 at 7:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.