Or in the Fortran you can use the ISO C Binding and specify the names by which Fortran procedures will be seen by other languages and the linker, specifying case and not needing underscores. You can also declare variables so that compatibility with C is guaranteed. In your example, Fortran default real
and C double
probably don't match. See https://stackoverflow.com/questions/tagged/fortran-iso-c-binding or the gfortran manual (its part of the language standard and so the documentation there is more generally applicable). For this example:
SUBROUTINE mysum(a,b) bind ( C, name = "mysum" )
use iso_c_binding
implicit none
REAL (c_double) :: a,b,r
r = a+b
WRITE(*,*) r
END SUBROUTINE mysum