In Fortran2003, is 1D Assumed shape array interoperable with C?

佐手、 提交于 2021-02-05 08:36:06

问题


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.

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

The interface in fortran may like

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

while in C, the prototype maybe

int some_c_function(int *a)

Will that conform the Fortran 2003 standard?


回答1:


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.



来源:https://stackoverflow.com/questions/38349435/in-fortran2003-is-1d-assumed-shape-array-interoperable-with-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!