Fortran

Guide To Learn

Use Interoperability Features

Interface with C Code:

  • Use iso_c_binding to interface Fortran with C code, enabling the use of external libraries and functions written in C.

Example:

fortranCopy codemodule interface
    use iso_c_binding, only: c_double
    implicit none

    interface
        function c_function(x) bind(c)
            import :: c_double
            real(c_double) :: c_function
            real(c_double), value :: x
        end function c_function
    end interface
end module interface

program call_c
    use interface
    implicit none
    real(c_double) :: result

    result = c_function(3.0)
    print *, 'Result from C function:', result
end program call_c
Use Interoperability Features

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top