Fortran Coder

查看: 8605|回复: 2
打印 上一主题 下一主题

[混编] 如何实现fortran调c,同时c调fortran

[复制链接]

1967

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1370 元
贡献
581 点

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

楼主
发表于 2016-1-9 13:35:38 | 显示全部楼层
[C] 纯文本查看 复制代码
#include <stdio.h>
typedef int(*pSSptr) (int *a);
void print_a_( pSSptr ss_ ,int *a ){
  ss_( a );  //调用传递进来的子程序
  printf( "ca=%d\n" , *a );
}


[Fortran] 纯文本查看 复制代码
Program voi0d
  use ISO_C_BINDING
  implicit none
  external :: ss
  interface
    subroutine print_a(s,a) bind(C,name='print_a_')
      import
      type(C_FUNPTR) , value :: s
      type(C_PTR) , value :: a
    end subroutine print_a
  end interface
  integer , target :: a = 256
  call print_a( c_funloc(ss) , c_loc(a) )
  print * , a
End Program voi0d
 !************************************
    !  需要传递的子程序如下:
 !************************************
   subroutine ss(a) Bind( c )
    implicit none
    integer a
    a = a + 1
    print *,'a=',a
   end subroutine ss


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

本版积分规则

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

GMT+8, 2024-5-17 17:55

Powered by Tencent X3.4

© 2013-2024 Tencent

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