如何比较Fortran c_ptr和null

时间:2015-08-24 05:13:57

标签: fortran fortran-iso-c-binding

我有一些需要合并的Fortran和C代码。

我正在使用看起来像这样的Fortran界面:

module bridge
  use, intrinsic::iso_c_binding, only : c_ptr, c_null_ptr
  implicit none

  type(c_ptr) :: instance

  interface

    function c_init() result(this) bind(C, name="bridge_init")
      import
      type(c_ptr) :: this
    end function c_init

  end interface

contains

    subroutine init() 
      instance = c_init()
    end subroutine init

end module bridge

我的问题是我想在init子例程中检查初始化,例如

subroutine init()
  if( instance .eq. c_null_ptr ) then
    instance = c_init()
  end if
end subroutine

但这会给我Syntax error, found END-OF-STATEMENT when expecting one of: BLOCK BLOCKDATA PROGRAM MODULE TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS后跟This binary operation is invalid for this data type.

那么我应该使用什么呢?

0 个答案:

没有答案