C_F_POINTER — Convert C into Fortran pointer ¶CALL C_F_POINTER(CPTR, FPTR[, SHAPE, LOWER])
C_F_POINTER(CPTR, FPTR[, SHAPE, LOWER]) assigns the target of the C
pointer CPTR to the Fortran pointer FPTR and specifies its shape.
For an array FPTR, the lower bounds are specified by LOWER if
present and otherwise equal to 1.
Subroutine
| CPTR | scalar of the type C_PTR. It is
INTENT(IN). |
| FPTR | pointer interoperable with cptr. It is
INTENT(OUT). |
| SHAPE | (Optional) Rank-one array of type INTEGER
with INTENT(IN). It shall be present if and only if FPTR is an
array. The size must be equal to the rank of FPTR. |
| LOWER | (Optional) Rank-one array of type INTEGER
with INTENT(IN). It shall not be present if SHAPE is not present.
The size must be equal to the rank of FPTR. |
program main
use iso_c_binding
implicit none
interface
subroutine my_routine(p) bind(c,name='myC_func')
import :: c_ptr
type(c_ptr), intent(out) :: p
end subroutine
end interface
type(c_ptr) :: cptr
real,pointer :: a(:)
call my_routine(cptr)
call c_f_pointer(cptr, a, [12])
end program main
Fortran 2003 and later, with LOWER argument Fortran 2023 and later
C_LOC — Obtain the C address of an object,
C_F_PROCPOINTER — Convert C into Fortran procedure pointer