Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Fortran c_ptr null?

I have a type with two pointers, one Fortran pointer and one C pointer:

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

I can assign something to both pointers like:

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

When I want to initialize the pointers without assigning something, I can use null() or nullify for the Fortran pointer:

instance%fortranPointer => null()

But how can I initialize the c_ptr to null? instance%cPointer = null() is not working as null() is not allowed on the right hand side of an assignement. c_loc(null()) is not allowed as null() is not a variable, which location can be obtained.

Is there something like a c_null?

like image 919
PVitt Avatar asked Oct 24 '25 06:10

PVitt


1 Answers

Figured out that there is a intrinsic type named constant c_null_ptr that can be used.

like image 84
PVitt Avatar answered Oct 27 '25 02:10

PVitt