Module C_Interfaces Use, Intrinsic :: iso_c_binding Interface Subroutine cfunc_int(i) bind(c,name='printint') Use, Intrinsic :: iso_c_binding Integer(kind=c_int), value :: i End Subroutine End Interface Interface Subroutine cfunc_intptr(i) bind(c,name='printintptr') Use, Intrinsic :: iso_c_binding Type(C_Ptr), value :: i End Subroutine End Interface Interface Subroutine cfunc_intarray(i,n) bind(c,name='printintarray') Use, Intrinsic :: iso_c_binding Type(C_Ptr), value :: i Integer(c_int), value :: n End Subroutine End Interface Interface Subroutine cfunc_chararray(s,n) bind(c,name='printconstcharlist') Use, Intrinsic :: iso_c_binding Type(C_Ptr),dimension(*) :: s Integer(kind=c_int), value :: n End Subroutine cfunc_chararray End Interface Interface Integer(kind=c_int) Function incint(i) bind(c) Use, Intrinsic :: iso_c_binding Integer(kind=c_int), value :: i End Function End Interface Interface Integer(kind=c_int) Function incintptr(i) bind(c) Use, Intrinsic :: iso_c_binding Type(C_Ptr), value :: i End Function End Interface End Module C_Interfaces Program main Use C_Interfaces implicit none Integer(kind=c_int) :: i, j, n Integer(kind=c_int), target :: iptr Integer(Kind=C_int), Dimension(:), Pointer :: ip_array Integer(Kind=C_int), Dimension(:), Allocatable, Target :: it_array Character(len=99,kind=C_char), dimension(:), Pointer :: sp_array Type(C_Ptr), Dimension(:),Pointer :: S_Ptr i = 12 Call cfunc_int(i) iptr=13 Call cfunc_intptr(c_loc(iptr)) n = 5 Allocate(ip_array(n)) Allocate(it_array(n)) Do i = 1, n ip_array(i) = i End Do it_array = ip_array Call cfunc_intarray(c_loc(it_array),n) DeAllocate(ip_array) DeAllocate(it_array) Allocate(sp_array(n)) Allocate(S_Ptr(n)) Do i = 1, n Write(sp_array(i), 100) i,C_NULL_CHAR End Do 100 format('*** sp_array /',I5,'/ ***',A) Do i = 1, n S_Ptr(i) = C_loc(sp_array(i)) End Do Call cfunc_chararray(S_Ptr, n) DeAllocate(sp_array) DeAllocate(S_Ptr) i = incint(n) Write(*,*) 'inc(',n,')=',i i = incintptr(c_loc(iptr)) Write(*,*) 'inc(',iptr,')=',i Write(*,*) 'All done!' End Program main