]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/doc/gfortran/gnu-fortran-command-options/options-for-interoperability-with-other-languages.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / gnu-fortran-command-options / options-for-interoperability-with-other-languages.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 .. _interoperability-options:
7
8 Options for interoperability with other languages
9 *************************************************
10
11 .. index:: c-prototypes, Generating C prototypes from Fortran BIND(C) enteties
12
13 .. option:: -fc-prototypes
14
15 This option will generate C prototypes from ``BIND(C)`` variable
16 declarations, types and procedure interfaces and writes them to
17 standard output. ``ENUM`` is not yet supported.
18
19 The generated prototypes may need inclusion of an appropriate header,
20 such as ``<stdint.h>`` or ``<stdlib.h>``. For types which are
21 not specified using the appropriate kind from the ``iso_c_binding``
22 module, a warning is added as a comment to the code.
23
24 For function pointers, a pointer to a function returning ``int``
25 without an explicit argument list is generated.
26
27 Example of use:
28
29 .. code-block:: shell-session
30
31 $ gfortran -fc-prototypes -fsyntax-only foo.f90 > foo.h
32
33 where the C code intended for interoperating with the Fortran code
34 then uses ``#include "foo.h"``.
35
36 .. index:: c-prototypes-external, Generating C prototypes from external procedures
37
38 .. option:: -fc-prototypes-external
39
40 This option will generate C prototypes from external functions and
41 subroutines and write them to standard output. This may be useful for
42 making sure that C bindings to Fortran code are correct. This option
43 does not generate prototypes for ``BIND(C)`` procedures, use
44 :option:`-fc-prototypes` for that.
45
46 The generated prototypes may need inclusion of an appropriate
47 header, such as ``<stdint.h>`` or ``<stdlib.h>``.
48
49 This is primarily meant for legacy code to ensure that existing C
50 bindings match what :command:`gfortran` emits. The generated C
51 prototypes should be correct for the current version of the compiler,
52 but may not match what other compilers or earlier versions of
53 :command:`gfortran` need. For new developments, use of the
54 ``BIND(C)`` features is recommended.
55
56 Example of use:
57
58 .. code-block:: shell-session
59
60 $ gfortran -fc-prototypes-external -fsyntax-only foo.f > foo.h
61
62 where the C code intended for interoperating with the Fortran code
63 then uses ``#include "foo.h"``.