C_F_POINTER(3) - [ISO_C_BINDING] Convert C into Fortran pointer
call c_f_pointer(cptr, fptr [,shape] )
subroutine c_f_pointer(cptr, fptr ,shape )type(c_ptr),intent(in) :: cprt type(TYPE),pointer,intent(out) :: fprt integer,intent(in),optional :: shape(:)
The Fortran pointer FPRT must be interoperable with CPTR
SHAPE is only specified if FPTR is an array.
C_F_POINTER(3) assigns the target (the C pointer CPTR) to the Fortran pointer FPTR and specifies its shape if FPTR points to an array.
o CPTR : scalar of the type c_ptr. It is INTENT(IN). o FPTR : pointer interoperable with CPTR. it is INTENT(OUT). o 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.
Sample program:
program demo_c_f_pointer 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 demo_c_f_pointer
Fortran 2003
C_LOC(3), C_F_PROCPOINTER(3), ISO_C_BINDING(3)
Fortran intrinsic descriptions
Nemo Release 3.1 | c_f_pointer (3fortran) | November 02, 2024 |