修改了一下,gcc编译无问题,至于为啥这么改,ivf的帮助文档有详细的混合编程说明
首先得明白,传址、传值
Fortran代码
[Fortran] 纯文本查看 复制代码 program fmain
use, intrinsic:: iso_c_binding
implicit none
interface
subroutine addnum(a, b) bind(c, name="AddNumber")
import
implicit none
type(c_ptr),value::a
integer(c_int),value, intent(in)::b
end subroutine
end interface
integer(c_int):: num
real(c_double),target:: res
num = 2
res = 1.0D0
call addnum(c_loc(res), num)
write(*, *)"Result:",res
end program
C代码
[C] 纯文本查看 复制代码 #include <stdio.h>
void AddNumber(double *res, int num)
{
printf("C\tInput:%f\n", *res);
*res += (double)num;
printf("C\tAdded:%f\n", *res);
} |