Among Fortran compilers, gfortran can be instructed to emit C function prototypes which can be put in a header file. Here’s how to do it with gfortran (see section Options for interoperability with other languages):
I’m not sure this works as expected. With my gfortran 15.1.0, the code:
program test
use iso_c_binding
implicit none
interface
function my_c_function(string) bind(c)
import :: c_int, c_char
integer(c_int) my_c_function
character(kind=c_char, len=*) string
end function
end interface
end program
I agree with you. I also discovered some gaps in the coverage of this option - even in my original example, the assumed shape array x(:) should use a descriptor.
There was some work on the -fc-prototypes option in May 2025,