c_loc -> c_ptr -> c_f_pointer round trip
Jeffrey Whitaker
whitaker.jeffrey@gmail.com
Mon Apr 24 22:23:00 GMT 2017
Hi: My use case is as follows. 1) create a non-interoperable fortran
derived type pointer (e.g. with allocatable components), then create
an opaque handle by passing it to c_loc, 2) pass this handle to
C/python, 3) pass this handle back from C/python and then to fortran,
convert it back to a fortran derived type pointer using c_f_pointer,
and deallocate the memory. I've tested this in gfortran and it
appears to work (the fortran memory is deallocated). I'm wondering is
this guaranteed by the standard, or am I just lucky? I could imagine
that if the auxillary metadata that fortran needs to deallocate the
memory is not in the memory that the c_ptr address points to it would
not work.
BTW: the test code I created is at
https://github.com/jswhit/fortran_derived_type.
Regards, Jeff
More information about the Fortran
mailing list