一维假定形状数组是否可以与C互操作

一维假定形状数组是否可以与C互操作

本文介绍了在Fortran2003中,一维假定形状数组是否可以与C互操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Fortran 2003中,可分配数组不能与C互操作.我认为这与存储在内存中的其他数组信息有关,这些信息可能会干扰C的解释.

In Fortran 2003, the allocatable array is not interoperable with C. I suppose this has something to do with additional array information stored in memory which might disturb the C interpretation.

但是,如果我将虚拟参数声明为1D假定形状数组怎么办?例如

But what if I declare a dummy argument as 1D assumed shape array? for example

subroutine outter_subroutine(ma, size_ma)
integer  :: size_ma
integer  :: ma(size_ma)

call fortran_subroutine(ma)

end subroutine

!-----------------------------

subroutine fortran_subroutine(a)
integer, intent(in) :: a(:)
integer,(kind=c_int):: ierr
...
ierr = some_c_function(a)
...
end subroutine

fortran中的界面可能喜欢

The interface in fortran may like

interface
function some_c_function(a)
integer(c_int) :: a(*)
end interface

在C语言中,原型可能

int some_c_function(int *a)

是否符合Fortran 2003标准?

Will that conform the Fortran 2003 standard?

推荐答案

C个可互操作的子例程不能具有假定的形状参数,但是您可以将一个假定的形状数组(或其他任何形式)传递给一个具有假定的大小参数的可互操作的子例程(一种(*)).如果数组不连续,则编译器可能必须创建一个临时数组才能做到这一点.

C interoperable subroutines cannot have assumed shape arguments, but you can pass an assumed shape array (or any other) to an interoperable subroutine which has an assumed size argument (a(*)). A temporary array may have to be created by the compiler to be able to do that if the array is not contiguous.

这篇关于在Fortran2003中,一维假定形状数组是否可以与C互操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 02:11