program main_fortran use, intrinsic :: iso_c_binding integer(c_int) :: i real(c_float) :: r common /com/ i, r INTERFACE subroutine sam end subroutine subroutine mc() bind(C,name='mc') end subroutine END INTERFACE call sam ! load COMMON block in fortran call mc ! Call C code that gets pointer to COMMON WRITE(*,'(A,I4,F6.2)')'Fortran has the block /com/ ', i, r end program main_fortran subroutine sam_c(comp) bind(C,name='sam_c') use, intrinsic :: iso_c_binding ! The C function mc calls sam_c() to get the ! location of the common block start. type(c_ptr) :: comp integer(c_int), TARGET :: i real(c_float) :: r common /com/ i, r ! Return a pointer to the first location of the common block. comp=c_loc(i) WRITE(*,'(A,I4,F6.2)')'Fortran has common block /com/ ', i, r return end subroutine sam_c subroutine sam ! This is the original Fortran function ! assigning values to the COMMON BLOCK integer :: i real :: r common /com/ i, r i = 786 r = 3.2 return end subroutine sam