]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/doc/gfortran/intrinsic-procedures/cfpointer.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / intrinsic-procedures / cfpointer.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. _c_f_pointer:
7
8 C_F_POINTER --- Convert C into Fortran pointer
9 **********************************************
10
11 .. index:: C_F_POINTER, pointer, convert C to Fortran
12
13 .. function:: C_F_POINTER(CPTR, FPTR, SHAPE)
14
15 ``C_F_POINTER(CPTR, FPTR[, SHAPE])`` assigns the target of the C pointer
16 :samp:`{CPTR}` to the Fortran pointer :samp:`{FPTR}` and specifies its shape.
17
18 :param CPTR:
19 scalar of the type ``C_PTR``. It is
20 ``INTENT(IN)``.
21
22 :param FPTR:
23 pointer interoperable with :samp:`{cptr}`. It is
24 ``INTENT(OUT)``.
25
26 :param SHAPE:
27 (Optional) Rank-one array of type ``INTEGER``
28 with ``INTENT(IN)``. It shall be present
29 if and only if :samp:`{fptr}` is an array. The size
30 must be equal to the rank of :samp:`{fptr}`.
31
32 Standard:
33 Fortran 2003 and later
34
35 Class:
36 Subroutine
37
38 Syntax:
39 .. code-block:: fortran
40
41 CALL C_F_POINTER(CPTR, FPTR[, SHAPE])
42
43 Example:
44 .. code-block:: fortran
45
46 program main
47 use iso_c_binding
48 implicit none
49 interface
50 subroutine my_routine(p) bind(c,name='myC_func')
51 import :: c_ptr
52 type(c_ptr), intent(out) :: p
53 end subroutine
54 end interface
55 type(c_ptr) :: cptr
56 real,pointer :: a(:)
57 call my_routine(cptr)
58 call c_f_pointer(cptr, a, [12])
59 end program main
60
61 See also:
62 :ref:`C_LOC`,
63 :ref:`C_F_PROCPOINTER`