如何使 Fortran c_ptr 为空?

How to make a Fortran c_ptr null?

我有一个有两个指针的类型,一个 Fortran 指针和一个 C 指针:

type mytype
  procedure(whatever), pointer, nopass :: fortranPointer
  type(c_ptr) :: cPointer
end type 

我可以为两个指针分配一些东西,例如:

type(mytype) :: instance
instance%fortranPointer => fPtrToSomething
instance%cPointer = c_loc(somethingElse)

当我想在不赋值的情况下初始化指针时,我可以使用 null()nullify 作为 Fortran 指针:

instance%fortranPointer => null()

但是如何将 c_ptr 初始化为 null? instance%cPointer = null() 不起作用,因为 null() 不允许出现在赋值的右侧。 c_loc(null())是不允许的,因为null()不是一个变量,可以得到哪个位置。

有没有类似 c_null 的东西?

发现有一个 内部类型 命名常量 c_null_ptr 可以使用。