[Fortran] 纯文本查看 复制代码
subroutine F_TEST1
integer :: x=5,y=5,i=0
real*4 ::z
integer*4 :: F_ogd
pointer(F_ogd_pointer,F_ogd)
INTERFACE
integer*4 FUNCTION GETVAR(VarName) BIND(C,NAME="getvar_fun")
USE,INTRINSIC :: ISO_C_BINDING
CHARACTER(KIND=C_CHAR),DIMENSION(*)::VarName
END FUNCTION GETVAR
END INTERFACE
F_ogd_pointer=GETVAR("testvar")
! F_ogd=5
! z=LOC(F_ogd)
WRITE (*,*) F_ogd
! WRITE (*,*) z
WRITE (*,*) F_ogd_pointer
end
[Fortran] 纯文本查看 复制代码
subroutine F_TEST1
use , intrinsic :: ISO_C_Binding !//使用标准C接口模块
implicit none
integer :: x=5,y=5,i=0
real*4 ::z
integer*4 , pointer :: F_ogd !// fortran 指针
!//pointer(F_ogd_pointer,F_ogd) 这句删掉,是IVF的扩展语法
INTERFACE
type(C_PTR) FUNCTION GETVAR(VarName) BIND(C,NAME="getvar_fun") !//用 c_ptr 返回 C 指针
USE,INTRINSIC :: ISO_C_BINDING
CHARACTER(KIND=C_CHAR),DIMENSION(*)::VarName
END FUNCTION GETVAR
END INTERFACE
call c_f_pointer( GETVAR("testvar") , F_ogd ) !// 用 c_f_pointer 转换 fortran 指针
WRITE (*,*) F_ogd
end