I have a Fortran derived type with dynamically allocated memory.
TYPE :: A
REAL, DIMENSION(:), POINTER :: array_of_reals
END TYPE A
To pass this derived type to C, I have a C struct
struct A_struct {
double* array_of_reals
}
When I pass the Fortran type to C, I convert the Fortran pointer to C pointer using
C_LOC(array_of_reals)
This works fine.
Now, if I have an array of TYPE A,
TYPE A_Array
TYPE(A), DIMENSION(:), ALLOCATABLE :: array_of_A
END TYPE A_Array
I cannot simply pass C_LOC(array_of_A) to C because the memory pointer allocated in each element of array_of_A is not compatible with C. Is this correct? If so, how can I pass an array of derived type that contain dynamically allocated memory?
It seems I need to pass an array of C pointers
TYPE(C_PTR), DIMENSION(:), ALLOCATABLE :: array_of_A
but this won't work because I cannot use dynamic arrays with BIND(C).