Intel® Fortran Compiler 17.0 Developer Guide and Reference
For interoperating with C pointers, the module ISO_C_BINDING contains the derived types C_PTR and C_FUNPTR, which are interoperable with C object and function type pointers, respectively.
These types, as well as certain procedures in the module, provide the mechanism for passing dynamic arrays between the two languages. Because its elements do not need to be contiguous in memory, a Fortran pointer target or assumed-shape array cannot be passed to C. However, you can pass an allocated allocatable array to C, and you can associate an array allocated in C with a Fortran pointer. Additionally, as shown in the following, you can convert a pointer in C format to one in Fortran format.
Fortran Program Example |
---|
|
C Module Example |
---|
#include <stdlib.h> int *make_array(int n_elements) { int *parray; int i; parray = (int*) malloc(n_elements * sizeof(int)); for (i = 0; i < n_elements; i++) { parray[i] = i+1; } return parray; } |