【发布时间】:2012-03-13 14:56:44
【问题描述】:
我正在编写代码,它将使用 Fortran 的 C 互操作性机制(在 Fortran 2003 中引入并在较新版本的 gfortran 和 ifort 中实现)从 Fortran 调用 C 函数。
This answer 几乎是我所需要的,但我不知道应该在 Fortran 中为如下所示的 C 函数使用什么接口声明:
int use_array(int n, char * array[]){
int i;
for(i=0; i<n; i++){
printf("Item %d = %s\n",i,array[i]);
}
return n;
}
我不清楚 Fortran 端接口的声明应该是什么:
interface
function use_array(n, x) bind(C)
use iso_c_binding
integer (c_int) use_array
integer (c_int), value :: n
character(c_char) WHAT_SHOULD_GO_HERE? :: x
end function use_array
end interface
我知道我也必须处理空终止问题。
【问题讨论】:
-
非常感谢用户 francescalus 帮助编辑了这个问题,通过在其末尾删除“谢谢”让我显得不那么礼貌。谢天谢地,像他们这样的用户能够阻止人们用日常礼貌提出难以理解的问题。
标签: c interop fortran fortran-iso-c-binding