Fortran Coder

查看: 8734|回复: 3
打印 上一主题 下一主题

[混编] 请教关于Fortran调C后返回值的问题

[复制链接]

1967

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1370 元
贡献
581 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

楼主
发表于 2017-2-27 18:35:41 | 显示全部楼层
[Fortran] 纯文本查看 复制代码
module interfaces
interface
integer function sum(a,n) Bind( C , Name = "sum" )
  use ,Intrinsic::ISO_C_Binding
  type(C_PTR) , value :: a 
  integer , value :: n
end function sum
end interface
end module interfaces

program main
  use interfaces
  use , intrinsic :: ISO_C_Binding
  implicit none
  integer , target :: x(5) = [1,2,3,4,5]
  write(*,*) "Sum=" , sum( c_loc(x) , size(x) )
end program main

[C] 纯文本查看 复制代码
int sum(int a[], int n)
{
int i,s=0;
for(i=0;i<n;i++)
s+=a[i];
return s;
}




您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-21 13:18

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表