1 @c Copyright (C) 2004-2013 Free Software Foundation, Inc.
2 @c This is part of the GNU Fortran manual.
3 @c For copying conditions, see the file gfortran.texi.
7 Copyright @copyright{} 2004-2013 Free Software Foundation, Inc.
9 Permission is granted to copy, distribute and/or modify this document
10 under the terms of the GNU Free Documentation License, Version 1.3 or
11 any later version published by the Free Software Foundation; with the
12 Invariant Sections being ``Funding Free Software'', the Front-Cover
13 Texts being (a) (see below), and with the Back-Cover Texts being (b)
14 (see below). A copy of the license is included in the gfdl(7) man page.
16 (a) The FSF's Front-Cover Text is:
20 (b) The FSF's Back-Cover Text is:
22 You have freedom to copy and modify this GNU Manual, like GNU
23 software. Copies published by the Free Software Foundation raise
24 funds for GNU development.
26 @c Set file name and title for the man page.
28 @settitle GNU Fortran compiler.
30 gfortran [@option{-c}|@option{-S}|@option{-E}]
31 [@option{-g}] [@option{-pg}] [@option{-O}@var{level}]
32 [@option{-W}@var{warn}@dots{}] [@option{-pedantic}]
33 [@option{-I}@var{dir}@dots{}] [@option{-L}@var{dir}@dots{}]
34 [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
35 [@option{-f}@var{option}@dots{}]
36 [@option{-m}@var{machine-option}@dots{}]
37 [@option{-o} @var{outfile}] @var{infile}@dots{}
39 Only the most useful options are listed here; see below for the
43 gpl(7), gfdl(7), fsf-funding(7),
44 cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1)
45 and the Info entries for @file{gcc}, @file{cpp}, @file{gfortran}, @file{as},
46 @file{ld}, @file{binutils} and @file{gdb}.
49 For instructions on reporting bugs, see
53 See the Info entry for @command{gfortran} for contributors to GCC and
58 @node Invoking GNU Fortran
59 @chapter GNU Fortran Command Options
60 @cindex GNU Fortran command options
61 @cindex command options
62 @cindex options, @command{gfortran} command
64 @c man begin DESCRIPTION
66 The @command{gfortran} command supports all the options supported by the
67 @command{gcc} command. Only options specific to GNU Fortran are documented
70 @xref{Invoking GCC,,GCC Command Options,gcc,Using the GNU Compiler
71 Collection (GCC)}, for information
72 on the non-Fortran-specific aspects of the @command{gcc} command (and,
73 therefore, the @command{gfortran} command).
75 @cindex options, negative forms
76 All GCC and GNU Fortran options
77 are accepted both by @command{gfortran} and by @command{gcc}
78 (as well as any other drivers built at the same time,
79 such as @command{g++}),
80 since adding GNU Fortran to the GCC distribution
81 enables acceptance of GNU Fortran options
82 by all of the relevant drivers.
84 In some cases, options have positive and negative forms;
85 the negative form of @option{-ffoo} would be @option{-fno-foo}.
86 This manual documents only one of these two forms, whichever
87 one is not the default.
91 * Option Summary:: Brief list of all @command{gfortran} options,
93 * Fortran Dialect Options:: Controlling the variant of Fortran language
95 * Preprocessing Options:: Enable and customize preprocessing.
96 * Error and Warning Options:: How picky should the compiler be?
97 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
98 * Directory Options:: Where to find module files
99 * Link Options :: Influencing the linking step
100 * Runtime Options:: Influencing runtime behavior
101 * Code Gen Options:: Specifying conventions for function calls, data layout
103 * Environment Variables:: Environment variables that affect @command{gfortran}.
107 @section Option summary
111 Here is a summary of all the options specific to GNU Fortran, grouped
112 by type. Explanations are in the following sections.
115 @item Fortran Language Options
116 @xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
117 @gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
118 -fd-lines-as-comments -fdefault-double-8 -fdefault-integer-8 @gol
119 -fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
120 -ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
121 -ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
122 -fmax-identifier-length -fmodule-private -fno-fixed-form -fno-range-check @gol
123 -fopenmp -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 @gol
124 -freal-8-real-10 -freal-8-real-16 -freal-8-real-4 -std=@var{std}
127 @item Preprocessing Options
128 @xref{Preprocessing Options,,Enable and customize preprocessing}.
129 @gccoptlist{-A-@var{question}@r{[}=@var{answer}@r{]}
130 -A@var{question}=@var{answer} -C -CC -D@var{macro}@r{[}=@var{defn}@r{]}
132 -U@var{macro} -cpp -dD -dI -dM -dN -dU -fworking-directory
133 -imultilib @var{dir} @gol
134 -iprefix @var{file} -iquote -isysroot @var{dir} -isystem @var{dir} -nocpp
139 @item Error and Warning Options
140 @xref{Error and Warning Options,,Options to request or suppress errors
142 @gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
143 -Wc-binding-type -Wcharacter-truncation @gol
144 -Wconversion -Wfunction-elimination -Wimplicit-interface @gol
145 -Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol
146 -Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol
147 -Wsurprising -Wunderflow -Wunused-parameter -Wrealloc-lhs -Wrealloc-lhs-all @gol
148 -Wtarget-lifetime -fmax-errors=@var{n} -fsyntax-only -pedantic -pedantic-errors
151 @item Debugging Options
152 @xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
153 @gccoptlist{-fbacktrace -fdump-fortran-optimized -fdump-fortran-original @gol
154 -fdump-parse-tree -ffpe-trap=@var{list} -ffpe-summary=@var{list}
157 @item Directory Options
158 @xref{Directory Options,,Options for directory search}.
159 @gccoptlist{-I@var{dir} -J@var{dir} -fintrinsic-modules-path @var{dir}}
162 @xref{Link Options,,Options for influencing the linking step}.
163 @gccoptlist{-static-libgfortran}
165 @item Runtime Options
166 @xref{Runtime Options,,Options for influencing runtime behavior}.
167 @gccoptlist{-fconvert=@var{conversion} -fmax-subrecord-length=@var{length} @gol
168 -frecord-marker=@var{length} -fsign-zero
171 @item Code Generation Options
172 @xref{Code Gen Options,,Options for code generation conventions}.
173 @gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
174 -fbounds-check -fcheck-array-temporaries @gol
175 -fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
176 -fcoarray=@var{<none|single|lib>} -fexternal-blas -ff2c
177 -ffrontend-optimize @gol
178 -finit-character=@var{n} -finit-integer=@var{n} -finit-local-zero @gol
179 -finit-logical=@var{<true|false>}
180 -finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
181 -fmax-array-constructor=@var{n} -fmax-stack-var-size=@var{n}
182 -fno-align-commons @gol
183 -fno-automatic -fno-protect-parens -fno-underscoring @gol
184 -fsecond-underscore -fpack-derived -frealloc-lhs -frecursive @gol
185 -frepack-arrays -fshort-enums -fstack-arrays
189 @node Fortran Dialect Options
190 @section Options controlling Fortran dialect
191 @cindex dialect options
192 @cindex language, dialect options
193 @cindex options, dialect
195 The following options control the details of the Fortran dialect
196 accepted by the compiler:
201 @opindex @code{ffree-form}
202 @opindex @code{fno-fixed-form}
203 @cindex options, Fortran dialect
204 @cindex file format, free
205 @cindex file format, fixed
206 Specify the layout used by the source file. The free form layout
207 was introduced in Fortran 90. Fixed form was traditionally used in
208 older Fortran programs. When neither option is specified, the source
209 form is determined by the file extension.
211 @item -fall-intrinsics
212 @opindex @code{fall-intrinsics}
213 This option causes all intrinsic procedures (including the GNU-specific
214 extensions) to be accepted. This can be useful with @option{-std=f95} to
215 force standard-compliance but get access to the full range of intrinsics
216 available with @command{gfortran}. As a consequence, @option{-Wintrinsics-std}
217 will be ignored and no user-defined procedure with the same name as any
218 intrinsic will be called except when it is explicitly declared @code{EXTERNAL}.
220 @item -fd-lines-as-code
221 @itemx -fd-lines-as-comments
222 @opindex @code{fd-lines-as-code}
223 @opindex @code{fd-lines-as-comments}
224 Enable special treatment for lines beginning with @code{d} or @code{D}
225 in fixed form sources. If the @option{-fd-lines-as-code} option is
226 given they are treated as if the first column contained a blank. If the
227 @option{-fd-lines-as-comments} option is given, they are treated as
231 @opindex @code{fdollar-ok}
234 @cindex character set
235 Allow @samp{$} as a valid non-first character in a symbol name. Symbols
236 that start with @samp{$} are rejected since it is unclear which rules to
237 apply to implicit typing as different vendors implement different rules.
238 Using @samp{$} in @code{IMPLICIT} statements is also rejected.
241 @opindex @code{backslash}
243 @cindex escape characters
244 Change the interpretation of backslashes in string literals from a single
245 backslash character to ``C-style'' escape characters. The following
246 combinations are expanded @code{\a}, @code{\b}, @code{\f}, @code{\n},
247 @code{\r}, @code{\t}, @code{\v}, @code{\\}, and @code{\0} to the ASCII
248 characters alert, backspace, form feed, newline, carriage return,
249 horizontal tab, vertical tab, backslash, and NUL, respectively.
250 Additionally, @code{\x}@var{nn}, @code{\u}@var{nnnn} and
251 @code{\U}@var{nnnnnnnn} (where each @var{n} is a hexadecimal digit) are
252 translated into the Unicode characters corresponding to the specified code
253 points. All other combinations of a character preceded by \ are
256 @item -fmodule-private
257 @opindex @code{fmodule-private}
258 @cindex module entities
260 Set the default accessibility of module entities to @code{PRIVATE}.
261 Use-associated entities will not be accessible unless they are explicitly
262 declared as @code{PUBLIC}.
264 @item -ffixed-line-length-@var{n}
265 @opindex @code{ffixed-line-length-}@var{n}
266 @cindex file format, fixed
267 Set column after which characters are ignored in typical fixed-form
268 lines in the source file, and through which spaces are assumed (as
269 if padded to that length) after the ends of short fixed-form lines.
271 Popular values for @var{n} include 72 (the
272 standard and the default), 80 (card image), and 132 (corresponding
273 to ``extended-source'' options in some popular compilers).
274 @var{n} may also be @samp{none}, meaning that the entire line is meaningful
275 and that continued character constants never have implicit spaces appended
276 to them to fill out the line.
277 @option{-ffixed-line-length-0} means the same thing as
278 @option{-ffixed-line-length-none}.
280 @item -ffree-line-length-@var{n}
281 @opindex @code{ffree-line-length-}@var{n}
282 @cindex file format, free
283 Set column after which characters are ignored in typical free-form
284 lines in the source file. The default value is 132.
285 @var{n} may be @samp{none}, meaning that the entire line is meaningful.
286 @option{-ffree-line-length-0} means the same thing as
287 @option{-ffree-line-length-none}.
289 @item -fmax-identifier-length=@var{n}
290 @opindex @code{fmax-identifier-length=}@var{n}
291 Specify the maximum allowed identifier length. Typical values are
292 31 (Fortran 95) and 63 (Fortran 2003 and Fortran 2008).
294 @item -fimplicit-none
295 @opindex @code{fimplicit-none}
296 Specify that no implicit typing is allowed, unless overridden by explicit
297 @code{IMPLICIT} statements. This is the equivalent of adding
298 @code{implicit none} to the start of every procedure.
301 @opindex @code{fcray-pointer}
302 Enable the Cray pointer extension, which provides C-like pointer
306 @opindex @code{fopenmp}
308 Enable the OpenMP extensions. This includes OpenMP @code{!$omp} directives
310 and @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
311 @code{!$} conditional compilation sentinels in free form
312 and @code{c$}, @code{*$} and @code{!$} sentinels in fixed form,
313 and when linking arranges for the OpenMP runtime library to be linked
314 in. The option @option{-fopenmp} implies @option{-frecursive}.
316 @item -fno-range-check
317 @opindex @code{frange-check}
318 Disable range checking on results of simplification of constant
319 expressions during compilation. For example, GNU Fortran will give
320 an error at compile time when simplifying @code{a = 1. / 0}.
321 With this option, no error will be given and @code{a} will be assigned
322 the value @code{+Infinity}. If an expression evaluates to a value
323 outside of the relevant range of [@code{-HUGE()}:@code{HUGE()}],
324 then the expression will be replaced by @code{-Inf} or @code{+Inf}
326 Similarly, @code{DATA i/Z'FFFFFFFF'/} will result in an integer overflow
327 on most systems, but with @option{-fno-range-check} the value will
328 ``wrap around'' and @code{i} will be initialized to @math{-1} instead.
330 @item -fdefault-integer-8
331 @opindex @code{fdefault-integer-8}
332 Set the default integer and logical types to an 8 byte wide type.
333 Do nothing if this is already the default. This option also affects
334 the kind of integer constants like @code{42}.
336 @item -fdefault-real-8
337 @opindex @code{fdefault-real-8}
338 Set the default real type to an 8 byte wide type.
339 Do nothing if this is already the default. This option also affects
340 the kind of non-double real constants like @code{1.0}, and does promote
341 the default width of @code{DOUBLE PRECISION} to 16 bytes if possible, unless
342 @code{-fdefault-double-8} is given, too.
344 @item -fdefault-double-8
345 @opindex @code{fdefault-double-8}
346 Set the @code{DOUBLE PRECISION} type to an 8 byte wide type. If
347 @option{-fdefault-real-8} is given, @code{DOUBLE PRECISION} would
348 instead be promoted to 16 bytes if possible, and @option{-fdefault-double-8}
349 can be used to prevent this. The kind of real constants like @code{1.d0} will
350 not be changed by @option{-fdefault-real-8} though, so also
351 @option{-fdefault-double-8} does not affect it.
353 @item -finteger-4-integer-8
354 @opindex @code{finteger-4-integer-8}
355 Promote all @code{INTEGER(KIND=4)} entities to an @code{INTEGER(KIND=8)}
356 entities. If @code{KIND=8} is unavailable, then an error will be issued.
357 This option should be used with care and may not be suitable for your codes.
358 Areas of possible concern include calls to external procedures,
359 alignment in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
360 BOZ literal constant conversion, and I/O. Inspection of the intermediate
361 representation of the translated Fortran code, produced by
362 @option{-fdump-tree-original}, is suggested.
364 @item -freal-4-real-8
365 @itemx -freal-4-real-10
366 @itemx -freal-4-real-16
367 @itemx -freal-8-real-4
368 @itemx -freal-8-real-10
369 @itemx -freal-8-real-16
370 @opindex @code{freal-4-real-8}
371 @opindex @code{freal-4-real-10}
372 @opindex @code{freal-4-real-16}
373 @opindex @code{freal-8-real-4}
374 @opindex @code{freal-8-real-10}
375 @opindex @code{freal-8-real-16}
376 @cindex options, real kind type promotion
377 Promote all @code{REAL(KIND=M)} entities to @code{REAL(KIND=N)} entities.
378 If @code{REAL(KIND=N)} is unavailable, then an error will be issued.
379 All other real kind types are unaffected by this option.
380 These options should be used with care and may not be suitable for your
381 codes. Areas of possible concern include calls to external procedures,
382 alignment in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
383 BOZ literal constant conversion, and I/O. Inspection of the intermediate
384 representation of the translated Fortran code, produced by
385 @option{-fdump-tree-original}, is suggested.
388 @opindex @code{std=}@var{std} option
389 Specify the standard to which the program is expected to conform, which
390 may be one of @samp{f95}, @samp{f2003}, @samp{f2008}, @samp{gnu}, or
391 @samp{legacy}. The default value for @var{std} is @samp{gnu}, which
392 specifies a superset of the Fortran 95 standard that includes all of the
393 extensions supported by GNU Fortran, although warnings will be given for
394 obsolete extensions not recommended for use in new code. The
395 @samp{legacy} value is equivalent but without the warnings for obsolete
396 extensions, and may be useful for old non-standard programs. The
397 @samp{f95}, @samp{f2003} and @samp{f2008} values specify strict
398 conformance to the Fortran 95, Fortran 2003 and Fortran 2008 standards,
399 respectively; errors are given for all extensions beyond the relevant
400 language standard, and warnings are given for the Fortran 77 features
401 that are permitted but obsolescent in later standards. @samp{-std=f2008ts}
402 allows the Fortran 2008 standard including the additions of the
403 Technical Specification (TS) 29113 on Further Interoperability of Fortran
408 @node Preprocessing Options
409 @section Enable and customize preprocessing
411 @cindex options, preprocessor
414 Preprocessor related options. See section
415 @ref{Preprocessing and conditional compilation} for more detailed
416 information on preprocessing in @command{gfortran}.
423 @cindex preprocessor, enable
424 @cindex preprocessor, disable
425 Enable preprocessing. The preprocessor is automatically invoked if
426 the file extension is @file{.fpp}, @file{.FPP}, @file{.F}, @file{.FOR},
427 @file{.FTN}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}. Use
428 this option to manually enable preprocessing of any kind of Fortran file.
430 To disable preprocessing of files with any of the above listed extensions,
431 use the negative form: @option{-nocpp}.
433 The preprocessor is run in traditional mode. Any restrictions of the
434 file-format, especially the limits on line length, apply for
435 preprocessed output as well, so it might be advisable to use the
436 @option{-ffree-line-length-none} or @option{-ffixed-line-length-none}
441 @cindex preprocessor, debugging
442 @cindex debugging, preprocessor
443 Instead of the normal output, generate a list of @code{'#define'}
444 directives for all the macros defined during the execution of the
445 preprocessor, including predefined macros. This gives you a way
446 of finding out what is predefined in your version of the preprocessor.
447 Assuming you have no file @file{foo.f90}, the command
449 touch foo.f90; gfortran -cpp -E -dM foo.f90
451 will show all the predefined macros.
455 @cindex preprocessor, debugging
456 @cindex debugging, preprocessor
457 Like @option{-dM} except in two respects: it does not include the
458 predefined macros, and it outputs both the @code{#define} directives
459 and the result of preprocessing. Both kinds of output go to the
460 standard output file.
464 @cindex preprocessor, debugging
465 @cindex debugging, preprocessor
466 Like @option{-dD}, but emit only the macro names, not their expansions.
470 @cindex preprocessor, debugging
471 @cindex debugging, preprocessor
472 Like @option{dD} except that only macros that are expanded, or whose
473 definedness is tested in preprocessor directives, are output; the
474 output is delayed until the use or test of the macro; and @code{'#undef'}
475 directives are also output for macros tested but undefined at the time.
479 @cindex preprocessor, debugging
480 @cindex debugging, preprocessor
481 Output @code{'#include'} directives in addition to the result
484 @item -fworking-directory
485 @opindex @code{fworking-directory}
486 @cindex preprocessor, working directory
487 Enable generation of linemarkers in the preprocessor output that will
488 let the compiler know the current working directory at the time of
489 preprocessing. When this option is enabled, the preprocessor will emit,
490 after the initial linemarker, a second linemarker with the current
491 working directory followed by two slashes. GCC will use this directory,
492 when it is present in the preprocessed input, as the directory emitted
493 as the current working directory in some debugging information formats.
494 This option is implicitly enabled if debugging information is enabled,
495 but this can be inhibited with the negated form
496 @option{-fno-working-directory}. If the @option{-P} flag is present
497 in the command line, this option has no effect, since no @code{#line}
498 directives are emitted whatsoever.
500 @item -idirafter @var{dir}
501 @opindex @code{idirafter @var{dir}}
502 @cindex preprocessing, include path
503 Search @var{dir} for include files, but do it after all directories
504 specified with @option{-I} and the standard system directories have
505 been exhausted. @var{dir} is treated as a system include directory.
506 If dir begins with @code{=}, then the @code{=} will be replaced by
507 the sysroot prefix; see @option{--sysroot} and @option{-isysroot}.
509 @item -imultilib @var{dir}
510 @opindex @code{imultilib @var{dir}}
511 @cindex preprocessing, include path
512 Use @var{dir} as a subdirectory of the directory containing target-specific
515 @item -iprefix @var{prefix}
516 @opindex @code{iprefix @var{prefix}}
517 @cindex preprocessing, include path
518 Specify @var{prefix} as the prefix for subsequent @option{-iwithprefix}
519 options. If the @var{prefix} represents a directory, you should include
520 the final @code{'/'}.
522 @item -isysroot @var{dir}
523 @opindex @code{isysroot @var{dir}}
524 @cindex preprocessing, include path
525 This option is like the @option{--sysroot} option, but applies only to
526 header files. See the @option{--sysroot} option for more information.
528 @item -iquote @var{dir}
529 @opindex @code{iquote @var{dir}}
530 @cindex preprocessing, include path
531 Search @var{dir} only for header files requested with @code{#include "file"};
532 they are not searched for @code{#include <file>}, before all directories
533 specified by @option{-I} and before the standard system directories. If
534 @var{dir} begins with @code{=}, then the @code{=} will be replaced by the
535 sysroot prefix; see @option{--sysroot} and @option{-isysroot}.
537 @item -isystem @var{dir}
538 @opindex @code{isystem @var{dir}}
539 @cindex preprocessing, include path
540 Search @var{dir} for header files, after all directories specified by
541 @option{-I} but before the standard system directories. Mark it as a
542 system directory, so that it gets the same special treatment as is
543 applied to the standard system directories. If @var{dir} begins with
544 @code{=}, then the @code{=} will be replaced by the sysroot prefix;
545 see @option{--sysroot} and @option{-isysroot}.
548 @opindex @code{nostdinc}
549 Do not search the standard system directories for header files. Only
550 the directories you have specified with @option{-I} options (and the
551 directory of the current file, if appropriate) are searched.
554 @opindex @code{undef}
555 Do not predefine any system-specific or GCC-specific macros.
556 The standard predefined macros remain defined.
558 @item -A@var{predicate}=@var{answer}
559 @opindex @code{A@var{predicate}=@var{answer}}
560 @cindex preprocessing, assertion
561 Make an assertion with the predicate @var{predicate} and answer @var{answer}.
562 This form is preferred to the older form -A predicate(answer), which is still
563 supported, because it does not use shell special characters.
565 @item -A-@var{predicate}=@var{answer}
566 @opindex @code{A-@var{predicate}=@var{answer}}
567 @cindex preprocessing, assertion
568 Cancel an assertion with the predicate @var{predicate} and answer @var{answer}.
572 @cindex preprocessing, keep comments
573 Do not discard comments. All comments are passed through to the output
574 file, except for comments in processed directives, which are deleted
575 along with the directive.
577 You should be prepared for side effects when using @option{-C}; it causes
578 the preprocessor to treat comments as tokens in their own right. For example,
579 comments appearing at the start of what would be a directive line have the
580 effect of turning that line into an ordinary source line, since the first
581 token on the line is no longer a @code{'#'}.
583 Warning: this currently handles C-Style comments only. The preprocessor
584 does not yet recognize Fortran-style comments.
588 @cindex preprocessing, keep comments
589 Do not discard comments, including during macro expansion. This is like
590 @option{-C}, except that comments contained within macros are also passed
591 through to the output file where the macro is expanded.
593 In addition to the side-effects of the @option{-C} option, the @option{-CC}
594 option causes all C++-style comments inside a macro to be converted to C-style
595 comments. This is to prevent later use of that macro from inadvertently
596 commenting out the remainder of the source line. The @option{-CC} option
597 is generally used to support lint comments.
599 Warning: this currently handles C- and C++-Style comments only. The
600 preprocessor does not yet recognize Fortran-style comments.
603 @opindex @code{D@var{name}}
604 @cindex preprocessing, define macros
605 Predefine name as a macro, with definition @code{1}.
607 @item -D@var{name}=@var{definition}
608 @opindex @code{D@var{name}=@var{definition}}
609 @cindex preprocessing, define macros
610 The contents of @var{definition} are tokenized and processed as if they
611 appeared during translation phase three in a @code{'#define'} directive.
612 In particular, the definition will be truncated by embedded newline
615 If you are invoking the preprocessor from a shell or shell-like program
616 you may need to use the shell's quoting syntax to protect characters such
617 as spaces that have a meaning in the shell syntax.
619 If you wish to define a function-like macro on the command line, write
620 its argument list with surrounding parentheses before the equals sign
621 (if any). Parentheses are meaningful to most shells, so you will need
622 to quote the option. With sh and csh, @code{-D'name(args...)=definition'}
625 @option{-D} and @option{-U} options are processed in the order they are
626 given on the command line. All -imacros file and -include file options
627 are processed after all -D and -U options.
631 Print the name of each header file used, in addition to other normal
632 activities. Each name is indented to show how deep in the @code{'#include'}
637 @cindex preprocessing, no linemarkers
638 Inhibit generation of linemarkers in the output from the preprocessor.
639 This might be useful when running the preprocessor on something that
640 is not C code, and will be sent to a program which might be confused
644 @opindex @code{U@var{name}}
645 @cindex preprocessing, undefine macros
646 Cancel any previous definition of @var{name}, either built in or provided
647 with a @option{-D} option.
651 @node Error and Warning Options
652 @section Options to request or suppress errors and warnings
653 @cindex options, warnings
654 @cindex options, errors
655 @cindex warnings, suppressing
656 @cindex messages, error
657 @cindex messages, warning
658 @cindex suppressing warnings
660 Errors are diagnostic messages that report that the GNU Fortran compiler
661 cannot compile the relevant piece of source code. The compiler will
662 continue to process the program in an attempt to report further errors
663 to aid in debugging, but will not produce any compiled output.
665 Warnings are diagnostic messages that report constructions which
666 are not inherently erroneous but which are risky or suggest there is
667 likely to be a bug in the program. Unless @option{-Werror} is specified,
668 they do not prevent compilation of the program.
670 You can request many specific warnings with options beginning @option{-W},
671 for example @option{-Wimplicit} to request warnings on implicit
672 declarations. Each of these specific warning options also has a
673 negative form beginning @option{-Wno-} to turn off warnings;
674 for example, @option{-Wno-implicit}. This manual lists only one of the
675 two forms, whichever is not the default.
677 These options control the amount and kinds of errors and warnings produced
681 @item -fmax-errors=@var{n}
682 @opindex @code{fmax-errors=}@var{n}
683 @cindex errors, limiting
684 Limits the maximum number of error messages to @var{n}, at which point
685 GNU Fortran bails out rather than attempting to continue processing the
686 source code. If @var{n} is 0, there is no limit on the number of error
690 @opindex @code{fsyntax-only}
691 @cindex syntax checking
692 Check the code for syntax errors, but do not actually compile it. This
693 will generate module files for each module present in the code, but no
697 @opindex @code{pedantic}
698 Issue warnings for uses of extensions to Fortran 95.
699 @option{-pedantic} also applies to C-language constructs where they
700 occur in GNU Fortran source files, such as use of @samp{\e} in a
701 character constant within a directive like @code{#include}.
703 Valid Fortran 95 programs should compile properly with or without
705 However, without this option, certain GNU extensions and traditional
706 Fortran features are supported as well.
707 With this option, many of them are rejected.
709 Some users try to use @option{-pedantic} to check programs for conformance.
710 They soon find that it does not do quite what they want---it finds some
711 nonstandard practices, but not all.
712 However, improvements to GNU Fortran in this area are welcome.
714 This should be used in conjunction with @option{-std=f95},
715 @option{-std=f2003} or @option{-std=f2008}.
717 @item -pedantic-errors
718 @opindex @code{pedantic-errors}
719 Like @option{-pedantic}, except that errors are produced rather than
725 @cindex warnings, all
726 Enables commonly used warning options pertaining to usage that
727 we recommend avoiding and that we believe are easy to avoid.
728 This currently includes @option{-Waliasing}, @option{-Wampersand},
729 @option{-Wconversion}, @option{-Wsurprising}, @option{-Wc-binding-type},
730 @option{-Wintrinsics-std}, @option{-Wno-tabs}, @option{-Wintrinsic-shadow},
731 @option{-Wline-truncation}, @option{-Wtarget-lifetime},
732 @option{-Wreal-q-constant} and @option{-Wunused}.
735 @opindex @code{Waliasing}
737 @cindex warnings, aliasing
738 Warn about possible aliasing of dummy arguments. Specifically, it warns
739 if the same actual argument is associated with a dummy argument with
740 @code{INTENT(IN)} and a dummy argument with @code{INTENT(OUT)} in a call
741 with an explicit interface.
743 The following example will trigger the warning.
747 integer, intent(in) :: a
748 integer, intent(out) :: b
757 @opindex @code{Wampersand}
758 @cindex warnings, ampersand
760 Warn about missing ampersand in continued character constants. The warning is
761 given with @option{-Wampersand}, @option{-pedantic}, @option{-std=f95},
762 @option{-std=f2003} and @option{-std=f2008}. Note: With no ampersand
763 given in a continued character constant, GNU Fortran assumes continuation
764 at the first non-comment, non-whitespace character after the ampersand
765 that initiated the continuation.
767 @item -Warray-temporaries
768 @opindex @code{Warray-temporaries}
769 @cindex warnings, array temporaries
770 Warn about array temporaries generated by the compiler. The information
771 generated by this warning is sometimes useful in optimization, in order to
772 avoid such temporaries.
774 @item -Wc-binding-type
775 @opindex @code{Wc-binding-type}
776 @cindex warning, C binding type
777 Warn if the a variable might not be C interoperable. In particular, warn if
778 the variable has been declared using an intrinsic type with default kind
779 instead of using a kind parameter defined for C interoperability in the
780 intrinsic @code{ISO_C_Binding} module. This option is implied by
783 @item -Wcharacter-truncation
784 @opindex @code{Wcharacter-truncation}
785 @cindex warnings, character truncation
786 Warn when a character assignment will truncate the assigned string.
788 @item -Wline-truncation
789 @opindex @code{Wline-truncation}
790 @cindex warnings, line truncation
791 Warn when a source code line will be truncated. This option is
792 implied by @option{-Wall}.
795 @opindex @code{Wconversion}
796 @cindex warnings, conversion
798 Warn about implicit conversions that are likely to change the value of
799 the expression after conversion. Implied by @option{-Wall}.
801 @item -Wconversion-extra
802 @opindex @code{Wconversion-extra}
803 @cindex warnings, conversion
805 Warn about implicit conversions between different types and kinds.
808 @opindex @code{Wextra}
809 @cindex extra warnings
810 @cindex warnings, extra
811 Enables some warning options for usages of language features which
812 may be problematic. This currently includes @option{-Wcompare-reals}
813 and @option{-Wunused-parameter}.
815 @item -Wimplicit-interface
816 @opindex @code{Wimplicit-interface}
817 @cindex warnings, implicit interface
818 Warn if a procedure is called without an explicit interface.
819 Note this only checks that an explicit interface is present. It does not
820 check that the declared interfaces are consistent across program units.
822 @item -Wimplicit-procedure
823 @opindex @code{Wimplicit-procedure}
824 @cindex warnings, implicit procedure
825 Warn if a procedure is called that has neither an explicit interface
826 nor has been declared as @code{EXTERNAL}.
828 @item -Wintrinsics-std
829 @opindex @code{Wintrinsics-std}
830 @cindex warnings, non-standard intrinsics
831 @cindex warnings, intrinsics of other standards
832 Warn if @command{gfortran} finds a procedure named like an intrinsic not
833 available in the currently selected standard (with @option{-std}) and treats
834 it as @code{EXTERNAL} procedure because of this. @option{-fall-intrinsics} can
835 be used to never trigger this behavior and always link to the intrinsic
836 regardless of the selected standard.
838 @item -Wreal-q-constant
839 @opindex @code{Wreal-q-constant}
840 @cindex warnings, @code{q} exponent-letter
841 Produce a warning if a real-literal-constant contains a @code{q}
845 @opindex @code{Wsurprising}
846 @cindex warnings, suspicious code
847 Produce a warning when ``suspicious'' code constructs are encountered.
848 While technically legal these usually indicate that an error has been made.
850 This currently produces a warning under the following circumstances:
854 An INTEGER SELECT construct has a CASE that can never be matched as its
855 lower value is greater than its upper value.
858 A LOGICAL SELECT construct has three CASE statements.
861 A TRANSFER specifies a source that is shorter than the destination.
864 The type of a function result is declared more than once with the same type. If
865 @option{-pedantic} or standard-conforming mode is enabled, this is an error.
868 A @code{CHARACTER} variable is declared with negative length.
872 @opindex @code{Wtabs}
873 @cindex warnings, tabs
875 By default, tabs are accepted as whitespace, but tabs are not members
876 of the Fortran Character Set. For continuation lines, a tab followed
877 by a digit between 1 and 9 is supported. @option{-Wno-tabs} will cause
878 a warning to be issued if a tab is encountered. Note, @option{-Wno-tabs}
879 is active for @option{-pedantic}, @option{-std=f95}, @option{-std=f2003},
880 @option{-std=f2008} and @option{-Wall}.
883 @opindex @code{Wunderflow}
884 @cindex warnings, underflow
886 Produce a warning when numerical constant expressions are
887 encountered, which yield an UNDERFLOW during compilation.
889 @item -Wintrinsic-shadow
890 @opindex @code{Wintrinsic-shadow}
891 @cindex warnings, intrinsic
893 Warn if a user-defined procedure or module procedure has the same name as an
894 intrinsic; in this case, an explicit interface or @code{EXTERNAL} or
895 @code{INTRINSIC} declaration might be needed to get calls later resolved to
896 the desired intrinsic/procedure. This option is implied by @option{-Wall}.
898 @item -Wunused-dummy-argument
899 @opindex @code{Wunused-dummy-argument}
900 @cindex warnings, unused dummy argument
901 @cindex unused dummy argument
902 @cindex dummy argument, unused
903 Warn about unused dummy arguments. This option is implied by @option{-Wall}.
905 @item -Wunused-parameter
906 @opindex @code{Wunused-parameter}
907 @cindex warnings, unused parameter
908 @cindex unused parameter
909 Contrary to @command{gcc}'s meaning of @option{-Wunused-parameter},
910 @command{gfortran}'s implementation of this option does not warn
911 about unused dummy arguments (see @option{-Wunused-dummy-argument}),
912 but about unused @code{PARAMETER} values. @option{-Wunused-parameter}
913 is not included in @option{-Wall} but is implied by @option{-Wall -Wextra}.
915 @item -Walign-commons
916 @opindex @code{Walign-commons}
917 @cindex warnings, alignment of @code{COMMON} blocks
918 @cindex alignment of @code{COMMON} blocks
919 By default, @command{gfortran} warns about any occasion of variables being
920 padded for proper alignment inside a @code{COMMON} block. This warning can be turned
921 off via @option{-Wno-align-commons}. See also @option{-falign-commons}.
923 @item -Wfunction-elimination
924 @opindex @code{Wfunction-elimination}
925 @cindex function elimination
926 @cindex warnings, function elimination
927 Warn if any calls to functions are eliminated by the optimizations
928 enabled by the @option{-ffrontend-optimize} option.
931 @opindex @code{Wrealloc-lhs}
932 @cindex Reallocate the LHS in assignments, notification
933 Warn when the compiler might insert code to for allocation or reallocation of
934 an allocatable array variable of intrinsic type in intrinsic assignments. In
935 hot loops, the Fortran 2003 reallocation feature may reduce the performance.
936 If the array is already allocated with the correct shape, consider using a
937 whole-array array-spec (e.g. @code{(:,:,:)}) for the variable on the left-hand
938 side to prevent the reallocation check. Note that in some cases the warning
939 is shown, even if the compiler will optimize reallocation checks away. For
940 instance, when the right-hand side contains the same variable multiplied by
941 a scalar. See also @option{-frealloc-lhs}.
943 @item -Wrealloc-lhs-all
944 @opindex @code{Wrealloc-lhs-all}
945 Warn when the compiler inserts code to for allocation or reallocation of an
946 allocatable variable; this includes scalars and derived types.
948 @item -Wcompare-reals
949 @opindex @code{Wcompare-reals}
950 Warn when comparing real or complex types for equality or inequality.
951 This option is implied by @option{-Wextra}.
953 @item -Wtarget-lifetime
954 @opindex @code{Wtargt-lifetime}
955 Warn if the pointer in a pointer assignment might be longer than the its
956 target. This option is implied by @option{-Wall}.
959 @opindex @code{Wzerotrip}
960 Warn if a @code{DO} loop is known to execute zero times at compile
961 time. This option is implied by @option{-Wall}.
964 @opindex @code{Werror}
965 @cindex warnings, to errors
966 Turns all warnings into errors.
969 @xref{Warning Options,,Options to Request or Suppress Errors and
970 Warnings, gcc,Using the GNU Compiler Collection (GCC)}, for information on
971 more options offered by the GBE shared by @command{gfortran}, @command{gcc}
972 and other GNU compilers.
974 Some of these have no effect when compiling programs written in Fortran.
976 @node Debugging Options
977 @section Options for debugging your program or GNU Fortran
978 @cindex options, debugging
979 @cindex debugging information options
981 GNU Fortran has various special options that are used for debugging
982 either your program or the GNU Fortran compiler.
985 @item -fdump-fortran-original
986 @opindex @code{fdump-fortran-original}
987 Output the internal parse tree after translating the source program
988 into internal representation. Only really useful for debugging the
989 GNU Fortran compiler itself.
991 @item -fdump-optimized-tree
992 @opindex @code{fdump-fortran-optimized}
993 Output the parse tree after front-end optimization. Only really
994 useful for debugging the GNU Fortran compiler itself.
996 @opindex @code{fdump-parse-tree}
997 Output the internal parse tree after translating the source program
998 into internal representation. Only really useful for debugging the
999 GNU Fortran compiler itself. This option is deprecated; use
1000 @code{-fdump-fortran-original} instead.
1002 @item -ffpe-trap=@var{list}
1003 @opindex @code{ffpe-trap=}@var{list}
1004 Specify a list of floating point exception traps to enable. On most
1005 systems, if a floating point exception occurs and the trap for that
1006 exception is enabled, a SIGFPE signal will be sent and the program
1007 being aborted, producing a core file useful for debugging. @var{list}
1008 is a (possibly empty) comma-separated list of the following
1009 exceptions: @samp{invalid} (invalid floating point operation, such as
1010 @code{SQRT(-1.0)}), @samp{zero} (division by zero), @samp{overflow}
1011 (overflow in a floating point operation), @samp{underflow} (underflow
1012 in a floating point operation), @samp{inexact} (loss of precision
1013 during operation), and @samp{denormal} (operation performed on a
1014 denormal value). The first five exceptions correspond to the five
1015 IEEE 754 exceptions, whereas the last one (@samp{denormal}) is not
1016 part of the IEEE 754 standard but is available on some common
1017 architectures such as x86.
1019 The first three exceptions (@samp{invalid}, @samp{zero}, and
1020 @samp{overflow}) often indicate serious errors, and unless the program
1021 has provisions for dealing with these exceptions, enabling traps for
1022 these three exceptions is probably a good idea.
1024 Many, if not most, floating point operations incur loss of precision
1025 due to rounding, and hence the @code{ffpe-trap=inexact} is likely to
1026 be uninteresting in practice.
1028 By default no exception traps are enabled.
1030 @item -ffpe-summary=@var{list}
1031 @opindex @code{ffpe-summary=}@var{list}
1032 Specify a list of floating-point exceptions, whose flag status is printed
1033 to @code{ERROR_UNIT} when invoking @code{STOP} and @code{ERROR STOP}.
1034 @var{list} can be either @samp{none}, @samp{all} or a comma-separated list
1035 of the following exceptions: @samp{invalid}, @samp{zero}, @samp{overflow},
1036 @samp{underflow}, @samp{inexact} and @samp{denormal}. (See
1037 @option{-ffpe-trap} for a description of the exceptions.)
1039 By default, a summary for all exceptions but @samp{inexact} is shown.
1041 @item -fno-backtrace
1042 @opindex @code{fno-backtrace}
1045 When a serious runtime error is encountered or a deadly signal is
1046 emitted (segmentation fault, illegal instruction, bus error,
1047 floating-point exception, and the other POSIX signals that have the
1048 action @samp{core}), the Fortran runtime library tries to output a
1049 backtrace of the error. @code{-fno-backtrace} disables the backtrace
1050 generation. This option only has influence for compilation of the
1051 Fortran main program.
1055 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
1056 gcc,Using the GNU Compiler Collection (GCC)}, for more information on
1059 @node Directory Options
1060 @section Options for directory search
1061 @cindex directory, options
1062 @cindex options, directory search
1064 @cindex @code{INCLUDE} directive
1065 @cindex directive, @code{INCLUDE}
1066 These options affect how GNU Fortran searches
1067 for files specified by the @code{INCLUDE} directive and where it searches
1068 for previously compiled modules.
1070 It also affects the search paths used by @command{cpp} when used to preprocess
1075 @opindex @code{I}@var{dir}
1076 @cindex directory, search paths for inclusion
1077 @cindex inclusion, directory search paths for
1078 @cindex search paths, for included files
1079 @cindex paths, search
1080 @cindex module search path
1081 These affect interpretation of the @code{INCLUDE} directive
1082 (as well as of the @code{#include} directive of the @command{cpp}
1085 Also note that the general behavior of @option{-I} and
1086 @code{INCLUDE} is pretty much the same as of @option{-I} with
1087 @code{#include} in the @command{cpp} preprocessor, with regard to
1088 looking for @file{header.gcc} files and other such things.
1090 This path is also used to search for @file{.mod} files when previously
1091 compiled modules are required by a @code{USE} statement.
1093 @xref{Directory Options,,Options for Directory Search,
1094 gcc,Using the GNU Compiler Collection (GCC)}, for information on the
1098 @opindex @code{J}@var{dir}
1099 @opindex @code{M}@var{dir}
1100 @cindex paths, search
1101 @cindex module search path
1102 This option specifies where to put @file{.mod} files for compiled modules.
1103 It is also added to the list of directories to searched by an @code{USE}
1106 The default is the current directory.
1108 @item -fintrinsic-modules-path @var{dir}
1109 @opindex @code{fintrinsic-modules-path} @var{dir}
1110 @cindex paths, search
1111 @cindex module search path
1112 This option specifies the location of pre-compiled intrinsic modules, if
1113 they are not in the default location expected by the compiler.
1117 @section Influencing the linking step
1118 @cindex options, linking
1119 @cindex linking, static
1121 These options come into play when the compiler links object files into an
1122 executable output file. They are meaningless if the compiler is not doing
1126 @item -static-libgfortran
1127 @opindex @code{static-libgfortran}
1128 On systems that provide @file{libgfortran} as a shared and a static
1129 library, this option forces the use of the static version. If no
1130 shared version of @file{libgfortran} was built when the compiler was
1131 configured, this option has no effect.
1135 @node Runtime Options
1136 @section Influencing runtime behavior
1137 @cindex options, runtime
1139 These options affect the runtime behavior of programs compiled with GNU Fortran.
1142 @item -fconvert=@var{conversion}
1143 @opindex @code{fconvert=}@var{conversion}
1144 Specify the representation of data for unformatted files. Valid
1145 values for conversion are: @samp{native}, the default; @samp{swap},
1146 swap between big- and little-endian; @samp{big-endian}, use big-endian
1147 representation for unformatted files; @samp{little-endian}, use little-endian
1148 representation for unformatted files.
1150 @emph{This option has an effect only when used in the main program.
1151 The @code{CONVERT} specifier and the GFORTRAN_CONVERT_UNIT environment
1152 variable override the default specified by @option{-fconvert}.}
1154 @item -frecord-marker=@var{length}
1155 @opindex @code{frecord-marker=}@var{length}
1156 Specify the length of record markers for unformatted files.
1157 Valid values for @var{length} are 4 and 8. Default is 4.
1158 @emph{This is different from previous versions of @command{gfortran}},
1159 which specified a default record marker length of 8 on most
1160 systems. If you want to read or write files compatible
1161 with earlier versions of @command{gfortran}, use @option{-frecord-marker=8}.
1163 @item -fmax-subrecord-length=@var{length}
1164 @opindex @code{fmax-subrecord-length=}@var{length}
1165 Specify the maximum length for a subrecord. The maximum permitted
1166 value for length is 2147483639, which is also the default. Only
1167 really useful for use by the gfortran testsuite.
1170 @opindex @code{fsign-zero}
1171 When enabled, floating point numbers of value zero with the sign bit set
1172 are written as negative number in formatted output and treated as
1173 negative in the @code{SIGN} intrinsic. @option{-fno-sign-zero} does not
1174 print the negative sign of zero values (or values rounded to zero for I/O)
1175 and regards zero as positive number in the @code{SIGN} intrinsic for
1176 compatibility with Fortran 77. The default is @option{-fsign-zero}.
1179 @node Code Gen Options
1180 @section Options for code generation conventions
1181 @cindex code generation, conventions
1182 @cindex options, code generation
1183 @cindex options, run-time
1185 These machine-independent options control the interface conventions
1186 used in code generation.
1188 Most of them have both positive and negative forms; the negative form
1189 of @option{-ffoo} would be @option{-fno-foo}. In the table below, only
1190 one of the forms is listed---the one which is not the default. You
1191 can figure out the other form by either removing @option{no-} or adding
1195 @item -fno-automatic
1196 @opindex @code{fno-automatic}
1197 @cindex @code{SAVE} statement
1198 @cindex statement, @code{SAVE}
1199 Treat each program unit (except those marked as RECURSIVE) as if the
1200 @code{SAVE} statement were specified for every local variable and array
1201 referenced in it. Does not affect common blocks. (Some Fortran compilers
1202 provide this option under the name @option{-static} or @option{-save}.)
1203 The default, which is @option{-fautomatic}, uses the stack for local
1204 variables smaller than the value given by @option{-fmax-stack-var-size}.
1205 Use the option @option{-frecursive} to use no static memory.
1209 @cindex calling convention
1210 @cindex @command{f2c} calling convention
1211 @cindex @command{g77} calling convention
1212 @cindex libf2c calling convention
1213 Generate code designed to be compatible with code generated
1214 by @command{g77} and @command{f2c}.
1216 The calling conventions used by @command{g77} (originally implemented
1217 in @command{f2c}) require functions that return type
1218 default @code{REAL} to actually return the C type @code{double}, and
1219 functions that return type @code{COMPLEX} to return the values via an
1220 extra argument in the calling sequence that points to where to
1221 store the return value. Under the default GNU calling conventions, such
1222 functions simply return their results as they would in GNU
1223 C---default @code{REAL} functions return the C type @code{float}, and
1224 @code{COMPLEX} functions return the GNU C type @code{complex}.
1225 Additionally, this option implies the @option{-fsecond-underscore}
1226 option, unless @option{-fno-second-underscore} is explicitly requested.
1228 This does not affect the generation of code that interfaces with
1229 the @command{libgfortran} library.
1231 @emph{Caution:} It is not a good idea to mix Fortran code compiled with
1232 @option{-ff2c} with code compiled with the default @option{-fno-f2c}
1233 calling conventions as, calling @code{COMPLEX} or default @code{REAL}
1234 functions between program parts which were compiled with different
1235 calling conventions will break at execution time.
1237 @emph{Caution:} This will break code which passes intrinsic functions
1238 of type default @code{REAL} or @code{COMPLEX} as actual arguments, as
1239 the library implementations use the @option{-fno-f2c} calling conventions.
1241 @item -fno-underscoring
1242 @opindex @code{fno-underscoring}
1244 @cindex symbol names, underscores
1245 @cindex transforming symbol names
1246 @cindex symbol names, transforming
1247 Do not transform names of entities specified in the Fortran
1248 source file by appending underscores to them.
1250 With @option{-funderscoring} in effect, GNU Fortran appends one
1251 underscore to external names with no underscores. This is done to ensure
1252 compatibility with code produced by many UNIX Fortran compilers.
1254 @emph{Caution}: The default behavior of GNU Fortran is
1255 incompatible with @command{f2c} and @command{g77}, please use the
1256 @option{-ff2c} option if you want object files compiled with
1257 GNU Fortran to be compatible with object code created with these
1260 Use of @option{-fno-underscoring} is not recommended unless you are
1261 experimenting with issues such as integration of GNU Fortran into
1262 existing system environments (vis-@`{a}-vis existing libraries, tools,
1265 For example, with @option{-funderscoring}, and assuming other defaults like
1266 @option{-fcase-lower} and that @code{j()} and @code{max_count()} are
1267 external functions while @code{my_var} and @code{lvar} are local variables,
1270 I = J() + MAX_COUNT (MY_VAR, LVAR)
1273 is implemented as something akin to:
1275 i = j_() + max_count__(&my_var__, &lvar);
1278 With @option{-fno-underscoring}, the same statement is implemented as:
1281 i = j() + max_count(&my_var, &lvar);
1284 Use of @option{-fno-underscoring} allows direct specification of
1285 user-defined names while debugging and when interfacing GNU Fortran
1286 code with other languages.
1288 Note that just because the names match does @emph{not} mean that the
1289 interface implemented by GNU Fortran for an external name matches the
1290 interface implemented by some other language for that same name.
1291 That is, getting code produced by GNU Fortran to link to code produced
1292 by some other compiler using this or any other method can be only a
1293 small part of the overall solution---getting the code generated by
1294 both compilers to agree on issues other than naming can require
1295 significant effort, and, unlike naming disagreements, linkers normally
1296 cannot detect disagreements in these other areas.
1298 Also, note that with @option{-fno-underscoring}, the lack of appended
1299 underscores introduces the very real possibility that a user-defined
1300 external name will conflict with a name in a system library, which
1301 could make finding unresolved-reference bugs quite difficult in some
1302 cases---they might occur at program run time, and show up only as
1303 buggy behavior at run time.
1305 In future versions of GNU Fortran we hope to improve naming and linking
1306 issues so that debugging always involves using the names as they appear
1307 in the source, even if the names as seen by the linker are mangled to
1308 prevent accidental linking between procedures with incompatible
1311 @item -fsecond-underscore
1312 @opindex @code{fsecond-underscore}
1314 @cindex symbol names, underscores
1315 @cindex transforming symbol names
1316 @cindex symbol names, transforming
1317 @cindex @command{f2c} calling convention
1318 @cindex @command{g77} calling convention
1319 @cindex libf2c calling convention
1320 By default, GNU Fortran appends an underscore to external
1321 names. If this option is used GNU Fortran appends two
1322 underscores to names with underscores and one underscore to external names
1323 with no underscores. GNU Fortran also appends two underscores to
1324 internal names with underscores to avoid naming collisions with external
1327 This option has no effect if @option{-fno-underscoring} is
1328 in effect. It is implied by the @option{-ff2c} option.
1330 Otherwise, with this option, an external name such as @code{MAX_COUNT}
1331 is implemented as a reference to the link-time external symbol
1332 @code{max_count__}, instead of @code{max_count_}. This is required
1333 for compatibility with @command{g77} and @command{f2c}, and is implied
1334 by use of the @option{-ff2c} option.
1336 @item -fcoarray=@var{<keyword>}
1337 @opindex @code{fcoarray}
1342 Disable coarray support; using coarray declarations and image-control
1343 statements will produce a compile-time error. (Default)
1346 Single-image mode, i.e. @code{num_images()} is always one.
1349 Library-based coarray parallelization; a suitable GNU Fortran coarray
1350 library needs to be linked.
1354 @item -fcheck=@var{<keyword>}
1355 @opindex @code{fcheck}
1356 @cindex array, bounds checking
1357 @cindex bounds checking
1358 @cindex pointer checking
1359 @cindex memory checking
1360 @cindex range checking
1361 @cindex subscript checking
1362 @cindex checking subscripts
1363 @cindex run-time checking
1364 @cindex checking array temporaries
1366 Enable the generation of run-time checks; the argument shall be
1367 a comma-delimited list of the following keywords.
1371 Enable all run-time test of @option{-fcheck}.
1373 @item @samp{array-temps}
1374 Warns at run time when for passing an actual argument a temporary array
1375 had to be generated. The information generated by this warning is
1376 sometimes useful in optimization, in order to avoid such temporaries.
1378 Note: The warning is only printed once per location.
1381 Enable generation of run-time checks for array subscripts
1382 and against the declared minimum and maximum values. It also
1383 checks array indices for assumed and deferred
1384 shape arrays against the actual allocated bounds and ensures that all string
1385 lengths are equal for character array constructors without an explicit
1388 Some checks require that @option{-fcheck=bounds} is set for
1389 the compilation of the main program.
1391 Note: In the future this may also include other forms of checking, e.g.,
1392 checking substring references.
1395 Enable generation of run-time checks for invalid modification of loop
1396 iteration variables.
1399 Enable generation of run-time checks for memory allocation.
1400 Note: This option does not affect explicit allocations using the
1401 @code{ALLOCATE} statement, which will be always checked.
1403 @item @samp{pointer}
1404 Enable generation of run-time checks for pointers and allocatables.
1406 @item @samp{recursion}
1407 Enable generation of run-time checks for recursively called subroutines and
1408 functions which are not marked as recursive. See also @option{-frecursive}.
1409 Note: This check does not work for OpenMP programs and is disabled if used
1410 together with @option{-frecursive} and @option{-fopenmp}.
1414 @item -fbounds-check
1415 @opindex @code{fbounds-check}
1416 @c Note: This option is also referred in gcc's manpage
1417 Deprecated alias for @option{-fcheck=bounds}.
1419 @item -fcheck-array-temporaries
1420 @opindex @code{fcheck-array-temporaries}
1421 Deprecated alias for @option{-fcheck=array-temps}.
1423 @item -fmax-array-constructor=@var{n}
1424 @opindex @code{fmax-array-constructor}
1425 This option can be used to increase the upper limit permitted in
1426 array constructors. The code below requires this option to expand
1427 the array at compile time.
1433 integer, parameter :: n = 100000
1434 integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
1435 print '(10(I0,1X))', i
1439 @emph{Caution: This option can lead to long compile times and excessively
1440 large object files.}
1442 The default value for @var{n} is 65535.
1445 @item -fmax-stack-var-size=@var{n}
1446 @opindex @code{fmax-stack-var-size}
1447 This option specifies the size in bytes of the largest array that will be put
1448 on the stack; if the size is exceeded static memory is used (except in
1449 procedures marked as RECURSIVE). Use the option @option{-frecursive} to
1450 allow for recursive procedures which do not have a RECURSIVE attribute or
1451 for parallel programs. Use @option{-fno-automatic} to never use the stack.
1453 This option currently only affects local arrays declared with constant
1454 bounds, and may not apply to all character variables.
1455 Future versions of GNU Fortran may improve this behavior.
1457 The default value for @var{n} is 32768.
1459 @item -fstack-arrays
1460 @opindex @code{fstack-arrays}
1461 Adding this option will make the Fortran compiler put all local arrays,
1462 even those of unknown size onto stack memory. If your program uses very
1463 large local arrays it is possible that you will have to extend your runtime
1464 limits for stack memory on some operating systems. This flag is enabled
1465 by default at optimization level @option{-Ofast}.
1468 @item -fpack-derived
1469 @opindex @code{fpack-derived}
1470 @cindex structure packing
1471 This option tells GNU Fortran to pack derived type members as closely as
1472 possible. Code compiled with this option is likely to be incompatible
1473 with code compiled without this option, and may execute slower.
1475 @item -frepack-arrays
1476 @opindex @code{frepack-arrays}
1477 @cindex repacking arrays
1478 In some circumstances GNU Fortran may pass assumed shape array
1479 sections via a descriptor describing a noncontiguous area of memory.
1480 This option adds code to the function prologue to repack the data into
1481 a contiguous block at runtime.
1483 This should result in faster accesses to the array. However it can introduce
1484 significant overhead to the function call, especially when the passed data
1488 @opindex @code{fshort-enums}
1489 This option is provided for interoperability with C code that was
1490 compiled with the @option{-fshort-enums} option. It will make
1491 GNU Fortran choose the smallest @code{INTEGER} kind a given
1492 enumerator set will fit in, and give all its enumerators this kind.
1494 @item -fexternal-blas
1495 @opindex @code{fexternal-blas}
1496 This option will make @command{gfortran} generate calls to BLAS functions
1497 for some matrix operations like @code{MATMUL}, instead of using our own
1498 algorithms, if the size of the matrices involved is larger than a given
1499 limit (see @option{-fblas-matmul-limit}). This may be profitable if an
1500 optimized vendor BLAS library is available. The BLAS library will have
1501 to be specified at link time.
1503 @item -fblas-matmul-limit=@var{n}
1504 @opindex @code{fblas-matmul-limit}
1505 Only significant when @option{-fexternal-blas} is in effect.
1506 Matrix multiplication of matrices with size larger than (or equal to) @var{n}
1507 will be performed by calls to BLAS functions, while others will be
1508 handled by @command{gfortran} internal algorithms. If the matrices
1509 involved are not square, the size comparison is performed using the
1510 geometric mean of the dimensions of the argument and result matrices.
1512 The default value for @var{n} is 30.
1515 @opindex @code{frecursive}
1516 Allow indirect recursion by forcing all local arrays to be allocated
1517 on the stack. This flag cannot be used together with
1518 @option{-fmax-stack-var-size=} or @option{-fno-automatic}.
1520 @item -finit-local-zero
1521 @itemx -finit-integer=@var{n}
1522 @itemx -finit-real=@var{<zero|inf|-inf|nan|snan>}
1523 @itemx -finit-logical=@var{<true|false>}
1524 @itemx -finit-character=@var{n}
1525 @opindex @code{finit-local-zero}
1526 @opindex @code{finit-integer}
1527 @opindex @code{finit-real}
1528 @opindex @code{finit-logical}
1529 @opindex @code{finit-character}
1530 The @option{-finit-local-zero} option instructs the compiler to
1531 initialize local @code{INTEGER}, @code{REAL}, and @code{COMPLEX}
1532 variables to zero, @code{LOGICAL} variables to false, and
1533 @code{CHARACTER} variables to a string of null bytes. Finer-grained
1534 initialization options are provided by the
1535 @option{-finit-integer=@var{n}},
1536 @option{-finit-real=@var{<zero|inf|-inf|nan|snan>}} (which also initializes
1537 the real and imaginary parts of local @code{COMPLEX} variables),
1538 @option{-finit-logical=@var{<true|false>}}, and
1539 @option{-finit-character=@var{n}} (where @var{n} is an ASCII character
1540 value) options. These options do not initialize
1545 components of derived type variables
1547 variables that appear in an @code{EQUIVALENCE} statement.
1549 (These limitations may be removed in future releases).
1551 Note that the @option{-finit-real=nan} option initializes @code{REAL}
1552 and @code{COMPLEX} variables with a quiet NaN. For a signalling NaN
1553 use @option{-finit-real=snan}; note, however, that compile-time
1554 optimizations may convert them into quiet NaN and that trapping
1555 needs to be enabled (e.g. via @option{-ffpe-trap}).
1557 Finally, note that enabling any of the @option{-finit-*} options will
1558 silence warnings that would have been emitted by @option{-Wuninitialized}
1559 for the affected local variables.
1561 @item -falign-commons
1562 @opindex @code{falign-commons}
1563 @cindex alignment of @code{COMMON} blocks
1564 By default, @command{gfortran} enforces proper alignment of all variables in a
1565 @code{COMMON} block by padding them as needed. On certain platforms this is mandatory,
1566 on others it increases performance. If a @code{COMMON} block is not declared with
1567 consistent data types everywhere, this padding can cause trouble, and
1568 @option{-fno-align-commons} can be used to disable automatic alignment. The
1569 same form of this option should be used for all files that share a @code{COMMON} block.
1570 To avoid potential alignment issues in @code{COMMON} blocks, it is recommended to order
1571 objects from largest to smallest.
1573 @item -fno-protect-parens
1574 @opindex @code{fno-protect-parens}
1575 @cindex re-association of parenthesized expressions
1576 By default the parentheses in expression are honored for all optimization
1577 levels such that the compiler does not do any re-association. Using
1578 @option{-fno-protect-parens} allows the compiler to reorder @code{REAL} and
1579 @code{COMPLEX} expressions to produce faster code. Note that for the re-association
1580 optimization @option{-fno-signed-zeros} and @option{-fno-trapping-math}
1581 need to be in effect. The parentheses protection is enabled by default, unless
1582 @option{-Ofast} is given.
1585 @opindex @code{frealloc-lhs}
1586 @cindex Reallocate the LHS in assignments
1587 An allocatable left-hand side of an intrinsic assignment is automatically
1588 (re)allocated if it is either unallocated or has a different shape. The
1589 option is enabled by default except when @option{-std=f95} is given. See
1590 also @option{-Wrealloc-lhs}.
1592 @item -faggressive-function-elimination
1593 @opindex @code{faggressive-function-elimination}
1594 @cindex Elimination of functions with identical argument lists
1595 Functions with identical argument lists are eliminated within
1596 statements, regardless of whether these functions are marked
1597 @code{PURE} or not. For example, in
1601 there will only be a single call to @code{f}. This option only works
1602 if @option{-ffrontend-optimize} is in effect.
1604 @item -ffrontend-optimize
1605 @opindex @code{frontend-optimize}
1606 @cindex Front-end optimization
1607 This option performs front-end optimization, based on manipulating
1608 parts the Fortran parse tree. Enabled by default by any @option{-O}
1609 option. Optimizations enabled by this option include elimination of
1610 identical function calls within expressions, removing unnecessary
1611 calls to @code{TRIM} in comparisons and assignments and replacing
1612 @code{TRIM(a)} with @code{a(1:LEN_TRIM(a))}.
1613 It can be deselected by specifying @option{-fno-frontend-optimize}.
1616 @xref{Code Gen Options,,Options for Code Generation Conventions,
1617 gcc,Using the GNU Compiler Collection (GCC)}, for information on more options
1619 shared by @command{gfortran}, @command{gcc}, and other GNU compilers.
1623 @node Environment Variables
1624 @section Environment variables affecting @command{gfortran}
1625 @cindex environment variable
1627 @c man begin ENVIRONMENT
1629 The @command{gfortran} compiler currently does not make use of any environment
1630 variables to control its operation above and beyond those
1631 that affect the operation of @command{gcc}.
1633 @xref{Environment Variables,,Environment Variables Affecting GCC,
1634 gcc,Using the GNU Compiler Collection (GCC)}, for information on environment
1637 @xref{Runtime}, for environment variables that affect the
1638 run-time behavior of programs compiled with GNU Fortran.