Fortran Coder

查看: 7283|回复: 6
打印 上一主题 下一主题

[混编] C Fortran 混合编程

[复制链接]

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

楼主
发表于 2015-11-30 18:19:28 | 显示全部楼层
修改了一下,gcc编译无问题,至于为啥这么改,ivf的帮助文档有详细的混合编程说明
首先得明白,传址传值
Fortran代码
[Fortran] 纯文本查看 复制代码
program fmain
use, intrinsic:: iso_c_binding
implicit none
interface
	subroutine addnum(a, b) bind(c, name="AddNumber")
	import
	implicit none
	type(c_ptr),value::a
	integer(c_int),value, intent(in)::b
	end subroutine
end interface
integer(c_int):: num
real(c_double),target:: res
num = 2
res = 1.0D0
call addnum(c_loc(res), num)
write(*, *)"Result:",res
end program 

C代码
[C] 纯文本查看 复制代码
#include <stdio.h>

void AddNumber(double *res, int num)
{
	printf("C\tInput:%f\n", *res);
	*res += (double)num;
	printf("C\tAdded:%f\n", *res);
}

评分

参与人数 1贡献 +8 收起 理由
fcode + 8

查看全部评分

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

本版积分规则

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

GMT+8, 2024-5-12 19:20

Powered by Tencent X3.4

© 2013-2024 Tencent

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