Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从C++;到Fortran? 我有一个C++代码,我想调用FORTRAN中的一些函数。我有以下功能 Vector3d CWLiDAR__get_position(CWLiDAR* This) { return This->get_position(); }_C++_Fortran_Gfortran - Fatal编程技术网

如何从C++;到Fortran? 我有一个C++代码,我想调用FORTRAN中的一些函数。我有以下功能 Vector3d CWLiDAR__get_position(CWLiDAR* This) { return This->get_position(); }

如何从C++;到Fortran? 我有一个C++代码,我想调用FORTRAN中的一些函数。我有以下功能 Vector3d CWLiDAR__get_position(CWLiDAR* This) { return This->get_position(); },c++,fortran,gfortran,C++,Fortran,Gfortran,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_

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(*)
。这就是错误消息的原因。< /P>也许<代码>。数据()<代码>没有帮助,同样的错误。我应该作为一个例程来实现。是的,在C++中把它变成一个out参数。是的子程序,因为向量函数是FORTRAN,没有绑定(C),所以使用子程序。