我有一个 C++ 代码,我想在 Fortran 中调用一些函数。我有以下功能
Vector3d CWLiDAR__get_position(CWLiDAR* This)
{
return This->get_position();
}
Fortran 中有一个包装器:
module CWLiDAR_module
use, intrinsic :: ISO_C_Binding
implicit none
private
type CWLiDAR_type
private
type(C_ptr) :: object = C_NULL_ptr
end type CWLiDAR_type
interface
function C_CWLiDAR__get_position (this) result(pos) bind(C, name="CWLiDAR__get_position")
import
type(C_ptr), value :: this
real(C_double), intent(out), dimension(*) :: pos
end function C_CWLiDAR__get_position
end interface
interface get_position
module procedure CWLiDAR__get_position
end interface get_position
public :: get_position, CWLiDAR_type
contains
function CWLiDAR__get_position(this) result(pos)
type(CWLiDAR_type), intent(in) :: this
double precision, dimension(0:3) :: pos
pos = C_CWLiDAR__get_position(this%object)
end function CWLiDAR__get_position
end module CWLiDAR_module
但是我收到以下编译错误:
function C_CWLiDAR__get_position (this) result(pos) bind(C, name="CWL
1
Error: Assumed size array at (1) must be a dummy argument
function C_CWLiDAR__get_position (this) result(pos) bind(C, name="CWL
1
Error: Assumed size array at (1) must be a dummy argument
如何将 Vector3D 传递给 Fortran?
返回数组的函数不能与 C 互操作。你不能从 Fortran 调用这样的函数。至少不能便携地使用bind(C)
.
如果可能(但不是!),语法必须是
interface
function C_CWLiDAR__get_position (this) result(pos) bind(C, name="CWLiDAR__get_position")
import
type(C_ptr), value :: this
real(C_double), dimension(some_number) :: pos
end function C_CWLiDAR__get_position
end interface
编译器抱怨Fortran中既不允许intent
也dimension(*)
不允许函数结果。这就是错误消息的原因。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句