[C] 纯文本查看 复制代码
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
double c_add(double a[], int n)
{
int i;
double s=0;
double *xx ;
xx = calloc(n,sizeof(double));
for(i=0;i<n;++i)
xx=a+1;
printf("n/", xx );
return *xx;
}
[Fortran] 纯文本查看 复制代码
module interfaces
interface
real(8) function add(a,n) Bind( C , Name = "c_add" )
use ,Intrinsic::ISO_C_Binding
type(C_PTR) , value :: a
integer , value :: n
end function add
end interface
end module interfaces
program main
use interfaces
use , intrinsic :: ISO_C_Binding
implicit none
integer::i;
real(8) , target :: x(5) = [0.1,0.2,0.3,0.4,0.5]
do i=1,size(x)
write(*,*) add( c_loc(x) , size(x) )
end do
end program main