[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode module interfaces
interface
integer function sum(a,n) Bind( C , Name = "sum" )
use ,Intrinsic::ISO_C_Binding
type(C_PTR) , value :: a
integer , value :: n
end function sum
end interface
end module interfaces
program main
use interfaces
use , intrinsic :: ISO_C_Binding
implicit none
integer , target :: x(5) = [1,2,3,4,5]
write(*,*) "Sum=" , sum( c_loc(x) , size(x) )
end program main
[C] syntaxhighlighter_viewsource syntaxhighlighter_copycode int sum(int a[], int n)
{
int i,s=0;
for(i=0;i<n;i++)
s+=a[i];
return s;
}
|