我有一个有两个指针的类型,一个 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)
当我想初始化指针而不分配某些东西时,我可以对 Fortran 指针使用 null()
或 nullify
:
instance%fortranPointer => null()
但是如何将 c_ptr
初始化为 null? instance%cPointer = null()
不起作用,因为 null()
不允许出现在赋值的右侧。 c_loc(null())
是不允许的,因为null()
不是一个变量,可以获取哪个位置。
有没有类似c_null
的东西?
最佳答案
发现有一个名为常量c_null_ptr
的内在类型 可以使用。
关于pointers - 如何使 Fortran c_ptr 为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28148494/