]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
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 | .. _non-fortran-main-program: | |
7 | ||
8 | Non-Fortran Main Program | |
9 | ************************ | |
10 | ||
11 | .. toctree:: | |
12 | :maxdepth: 2 | |
13 | ||
14 | ||
15 | Even if you are doing mixed-language programming, it is very | |
16 | likely that you do not need to know or use the information in this | |
17 | section. Since it is about the internal structure of GNU Fortran, | |
18 | it may also change in GCC minor releases. | |
19 | ||
20 | When you compile a ``PROGRAM`` with GNU Fortran, a function | |
21 | with the name ``main`` (in the symbol table of the object file) | |
22 | is generated, which initializes the libgfortran library and then | |
23 | calls the actual program which uses the name ``MAIN__``, for | |
24 | historic reasons. If you link GNU Fortran compiled procedures | |
25 | to, e.g., a C or C++ program or to a Fortran program compiled by | |
26 | a different compiler, the libgfortran library is not initialized | |
27 | and thus a few intrinsic procedures do not work properly, e.g. | |
28 | those for obtaining the command-line arguments. | |
29 | ||
30 | Therefore, if your ``PROGRAM`` is not compiled with | |
31 | GNU Fortran and the GNU Fortran compiled procedures require | |
32 | intrinsics relying on the library initialization, you need to | |
33 | initialize the library yourself. Using the default options, | |
34 | gfortran calls ``_gfortran_set_args`` and | |
35 | ``_gfortran_set_options``. The initialization of the former | |
36 | is needed if the called procedures access the command line | |
37 | (and for backtracing); the latter sets some flags based on the | |
38 | standard chosen or to enable backtracing. In typical programs, | |
39 | it is not necessary to call any initialization function. | |
40 | ||
41 | If your ``PROGRAM`` is compiled with GNU Fortran, you shall | |
42 | not call any of the following functions. The libgfortran | |
43 | initialization functions are shown in C syntax but using C | |
44 | bindings they are also accessible from Fortran. | |
45 | ||
46 | .. index:: _gfortran_set_args, libgfortran initialization, set_args | |
47 | ||
48 | .. _gfortran_set_args: | |
49 | ||
50 | _gfortran_set_args --- Save command-line arguments | |
51 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
52 | ||
53 | .. function:: void _gfortran_set_args (int argc, char *argv[]) | |
54 | ||
55 | ``_gfortran_set_args`` saves the command-line arguments; this | |
56 | initialization is required if any of the command-line intrinsics | |
57 | is called. Additionally, it shall be called if backtracing is | |
58 | enabled (see ``_gfortran_set_options``). | |
59 | ||
60 | :param argc: | |
61 | number of command line argument strings | |
62 | ||
63 | :param argv: | |
64 | the command-line argument strings; argv[0] | |
65 | is the pathname of the executable itself. | |
66 | ||
67 | :samp:`{Example}:` | |
68 | ||
69 | .. code-block:: c | |
70 | ||
71 | int main (int argc, char *argv[]) | |
72 | { | |
73 | /* Initialize libgfortran. */ | |
74 | _gfortran_set_args (argc, argv); | |
75 | return 0; | |
76 | } | |
77 | ||
78 | .. index:: _gfortran_set_options, libgfortran initialization, set_options | |
79 | ||
80 | .. _gfortran_set_options: | |
81 | ||
82 | _gfortran_set_options --- Set library option flags | |
83 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
84 | ||
85 | .. function:: void _gfortran_set_options (int num, int options[]) | |
86 | ||
87 | ``_gfortran_set_options`` sets several flags related to the Fortran | |
88 | standard to be used, whether backtracing should be enabled | |
89 | and whether range checks should be performed. The syntax allows for | |
90 | upward compatibility since the number of passed flags is specified; for | |
91 | non-passed flags, the default value is used. See also | |
92 | see :ref:`code-gen-options`. Please note that not all flags are actually | |
93 | used. | |
94 | ||
95 | :param num: | |
96 | number of options passed | |
97 | ||
98 | :param argv: | |
99 | The list of flag values | |
100 | ||
101 | :samp:`{option flag list}:` | |
102 | ||
103 | .. list-table:: | |
104 | :widths: 15 85 | |
105 | ||
106 | * - :samp:`{option}` [0] | |
107 | - Allowed standard; can give run-time errors if e.g. an input-output edit descriptor is invalid in a given standard. Possible values are (bitwise or-ed) ``GFC_STD_F77`` (1), ``GFC_STD_F95_OBS`` (2), ``GFC_STD_F95_DEL`` (4), ``GFC_STD_F95`` (8), ``GFC_STD_F2003`` (16), ``GFC_STD_GNU`` (32), ``GFC_STD_LEGACY`` (64), ``GFC_STD_F2008`` (128), ``GFC_STD_F2008_OBS`` (256), ``GFC_STD_F2008_TS`` (512), ``GFC_STD_F2018`` (1024), ``GFC_STD_F2018_OBS`` (2048), and ``GFC_STD=F2018_DEL`` (4096). Default: ``GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77 | GFC_STD_F2018 | GFC_STD_F2018_OBS | GFC_STD_F2018_DEL | GFC_STD_GNU | GFC_STD_LEGACY``. | |
108 | * - :samp:`{option}` [1] | |
109 | - Standard-warning flag; prints a warning to standard error. Default: ``GFC_STD_F95_DEL | GFC_STD_LEGACY``. | |
110 | * - :samp:`{option}` [2] | |
111 | - If non zero, enable pedantic checking. Default: off. | |
112 | * - :samp:`{option}` [3] | |
113 | - Unused. | |
114 | * - :samp:`{option}` [4] | |
115 | - If non zero, enable backtracing on run-time errors. Default: off. (Default in the compiler: on.) Note: Installs a signal handler and requires command-line initialization using ``_gfortran_set_args``. | |
116 | * - :samp:`{option}` [5] | |
117 | - If non zero, supports signed zeros. Default: enabled. | |
118 | * - :samp:`{option}` [6] | |
119 | - Enables run-time checking. Possible values are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2), GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (8), GFC_RTCHECK_POINTER (16), GFC_RTCHECK_MEM (32), GFC_RTCHECK_BITS (64). Default: disabled. | |
120 | * - :samp:`{option}` [7] | |
121 | - Unused. | |
122 | * - :samp:`{option}` [8] | |
123 | - Show a warning when invoking ``STOP`` and ``ERROR STOP`` if a floating-point exception occurred. Possible values are (bitwise or-ed) ``GFC_FPE_INVALID`` (1), ``GFC_FPE_DENORMAL`` (2), ``GFC_FPE_ZERO`` (4), ``GFC_FPE_OVERFLOW`` (8), ``GFC_FPE_UNDERFLOW`` (16), ``GFC_FPE_INEXACT`` (32). Default: None (0). (Default in the compiler: ``GFC_FPE_INVALID | GFC_FPE_DENORMAL | GFC_FPE_ZERO | GFC_FPE_OVERFLOW | GFC_FPE_UNDERFLOW``.) | |
124 | ||
125 | :samp:`{Example}:` | |
126 | ||
127 | .. code-block:: c | |
128 | ||
129 | /* Use gfortran 4.9 default options. */ | |
130 | static int options[] = {68, 511, 0, 0, 1, 1, 0, 0, 31}; | |
131 | _gfortran_set_options (9, &options); | |
132 | ||
133 | .. index:: _gfortran_set_convert, libgfortran initialization, set_convert | |
134 | ||
135 | .. _gfortran_set_convert: | |
136 | ||
137 | _gfortran_set_convert --- Set endian conversion | |
138 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
139 | ||
140 | .. function:: void _gfortran_set_convert (int conv) | |
141 | ||
142 | ``_gfortran_set_convert`` set the representation of data for | |
143 | unformatted files. | |
144 | ||
145 | :param conv: | |
146 | Endian conversion, possible values: | |
147 | GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1), | |
148 | GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3). | |
149 | ||
150 | :samp:`{Example}:` | |
151 | ||
152 | .. code-block:: c | |
153 | ||
154 | int main (int argc, char *argv[]) | |
155 | { | |
156 | /* Initialize libgfortran. */ | |
157 | _gfortran_set_args (argc, argv); | |
158 | _gfortran_set_convert (1); | |
159 | return 0; | |
160 | } | |
161 | ||
162 | .. index:: _gfortran_set_record_marker, libgfortran initialization, set_record_marker | |
163 | ||
164 | .. _gfortran_set_record_marker: | |
165 | ||
166 | _gfortran_set_record_marker --- Set length of record markers | |
167 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
168 | ||
169 | .. function:: void _gfortran_set_record_marker (int val) | |
170 | ||
171 | ``_gfortran_set_record_marker`` sets the length of record markers | |
172 | for unformatted files. | |
173 | ||
174 | :param val: | |
175 | Length of the record marker; valid values | |
176 | are 4 and 8. Default is 4. | |
177 | ||
178 | :samp:`{Example}:` | |
179 | ||
180 | .. code-block:: c | |
181 | ||
182 | int main (int argc, char *argv[]) | |
183 | { | |
184 | /* Initialize libgfortran. */ | |
185 | _gfortran_set_args (argc, argv); | |
186 | _gfortran_set_record_marker (8); | |
187 | return 0; | |
188 | } | |
189 | ||
190 | .. index:: _gfortran_set_fpe, libgfortran initialization, set_fpe | |
191 | ||
192 | .. _gfortran_set_fpe: | |
193 | ||
194 | _gfortran_set_fpe --- Enable floating point exception traps | |
195 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
196 | ||
197 | .. function:: void _gfortran_set_fpe (int val) | |
198 | ||
199 | ``_gfortran_set_fpe`` enables floating point exception traps for | |
200 | the specified exceptions. On most systems, this will result in a | |
201 | SIGFPE signal being sent and the program being aborted. | |
202 | ||
203 | :param option} [0]: | |
204 | IEEE exceptions. Possible values are | |
205 | (bitwise or-ed) zero (0, default) no trapping, | |
206 | ``GFC_FPE_INVALID`` (1), ``GFC_FPE_DENORMAL`` (2), | |
207 | ``GFC_FPE_ZERO`` (4), ``GFC_FPE_OVERFLOW`` (8), | |
208 | ``GFC_FPE_UNDERFLOW`` (16), and ``GFC_FPE_INEXACT`` (32). | |
209 | ||
210 | :samp:`{Example}:` | |
211 | ||
212 | .. code-block:: c | |
213 | ||
214 | int main (int argc, char *argv[]) | |
215 | { | |
216 | /* Initialize libgfortran. */ | |
217 | _gfortran_set_args (argc, argv); | |
218 | /* FPE for invalid operations such as SQRT(-1.0). */ | |
219 | _gfortran_set_fpe (1); | |
220 | return 0; | |
221 | } | |
222 | ||
223 | .. index:: _gfortran_set_max_subrecord_length, libgfortran initialization, set_max_subrecord_length | |
224 | ||
225 | .. _gfortran_set_max_subrecord_length: | |
226 | ||
227 | _gfortran_set_max_subrecord_length --- Set subrecord length | |
228 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
229 | ||
230 | .. function:: void _gfortran_set_max_subrecord_length (int val) | |
231 | ||
232 | ``_gfortran_set_max_subrecord_length`` set the maximum length | |
233 | for a subrecord. This option only makes sense for testing and | |
234 | debugging of unformatted I/O. | |
235 | ||
236 | :param val: | |
237 | the maximum length for a subrecord; | |
238 | the maximum permitted value is 2147483639, which is also | |
239 | the default. | |
240 | ||
241 | :samp:`{Example}:` | |
242 | ||
243 | .. code-block:: c | |
244 | ||
245 | int main (int argc, char *argv[]) | |
246 | { | |
247 | /* Initialize libgfortran. */ | |
248 | _gfortran_set_args (argc, argv); | |
249 | _gfortran_set_max_subrecord_length (8); | |
250 | return 0; | |
3ed1b4ce | 251 | } |