问题
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