【发布时间】:2016-01-01 07:02:40
【问题描述】:
我在将 Fortran 程序与 C++ 函数连接时遇到问题。 我的任务是从fortran调用C++函数指针,例如:
// C++ function pointer
double* GetSplinePtr()
{
return sp;
}
我使用 iso_c_binding 程序和 fortran 接口。 对于非指针函数,我通常使用这个声明:
real(kind=c_double) function Name(x,y) bind(c, name='Name')
use iso_c_binding
implicit none
real(c_double), intent(in), value :: x,y
end function Name
但是对于返回指针的函数我应该使用什么?
谢谢!
【问题讨论】:
-
C_PTR这个类型呢,也是模块iso_c_binding的一个组件? -
您确定
intent(in)和value可以同时使用吗? -
@vladimirf
intent(inout)和intent(out)肯定与value冲突,但与intent(in)不冲突? -
是的,我记错了约束,它是(F2008):
C558 An entity with the VALUE attribute shall not have the ALLOCATABLE, INTENT (INOUT), INTENT (OUT), POINTER, or VOLATILE attributes. -
它是 C 还是 C++ 指针?如果它是 C++ 指针,则存在名称修饰。它应该在 C++ 端声明为 extern "C" 以避免名称混乱。