How to call Fortran routine with unit number argument from C

349 Views Asked by At

If I have a Fortran subroutine which takes a Fortran IO Unit as one of its parameters (for printing debug information to), and this function is compiled into a shared library, how do I correctly call this function from C?

! An example subroutine that I want to call from C:
subroutine hi(unit)
    integer :: unit
    write(unit,*) "hello"
end subroutine

! example call site in Fortran
program main
    call hi(6)
end

I am interested in how these unit numbers relate to file descriptors.

1

There are 1 best solutions below

6
On BEST ANSWER

This is completely compiler dependent, there is no portable correspondence. See the manual of your compiler if they support some sort of interoperability as an extension.