GFORTRAN(1)

๐Ÿ“ฆ
version 11.5.0 ยท 2 versions
, in ubuntu noble

๐ŸŽ€ GFORTRAN(1) ยท GNU Manual ๐ŸŽ€

โœจ NAME โœจ

okay so bestie, this is gfortran, aka the GNU Fortran compiler ๐Ÿ’…๐Ÿฆ‹

๐Ÿงš SYNOPSIS ๐Ÿงš

gfortran [-c|-S|-E]
         [-g] [-pg] [-Olevel]
         [-Wwarn...] [-pedantic]
         [-Idir...] [-Ldir...]
         [-Dmacro[=defn]...] [-Umacro]
         [-foption...]
         [-mmachine-option...]
         [-o outfile] infile...

Only the most useful options are squeezed into the synopsis, so scroll down for the rest ๐Ÿซถ

๐Ÿ’– DESCRIPTION ๐Ÿ’–

The gfortran command is literally giving gcc energy, because it supports all the options that gcc supports โœจ Only the options specific to GNU Fortran get documented here, so no need to re-read the GCC stuff ๐Ÿ™ˆ

All GCC and GNU Fortran options work with both gfortran and gcc, plus any other drivers built at the same time (like g++) ๐ŸŒˆ Adding GNU Fortran to the GCC distribution means every relevant driver accepts GNU Fortran options. Iconic, honestly ๐Ÿ‘‘

Some options come in pairs. The negative form of -ffoo is -fno-foo, and this manual only documents whichever one isn't the default ๐Ÿ’…

๐ŸŒˆ OPTIONS ๐ŸŒˆ

Here's the vibe check of every option specific to GNU Fortran, sorted into groups by type ๐Ÿ“ The explanations come in the sections after this summary ๐Ÿ’œ

๐Ÿฆ‹ Fortran Language Options ๐Ÿฆ‹

-fall-intrinsics -fallow-argument-mismatch -fallow-invalid-boz
-fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments
-fdec -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints
-fdec-static -fdec-math -fdec-include -fdec-format-defaults
-fdec-blank-format-item -fdefault-double-8 -fdefault-integer-8
-fdefault-real-8 -fdefault-real-10 -fdefault-real-16 -fdollar-ok
-ffixed-line-length-n -ffixed-line-length-none -fpad-source
-ffree-form -ffree-line-length-n -ffree-line-length-none
-fimplicit-none -finteger-4-integer-8 -fmax-identifier-length
-fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp
-freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10
-freal-8-real-16 -freal-8-real-4 -std=std -ftest-forall-temp

๐ŸŒธ Preprocessing Options ๐ŸŒธ

-A-question[=answer] -Aquestion=answer -C -CC -Dmacro[=defn] -H -P
-Umacro -cpp -dD -dI -dM -dN -dU -fworking-directory -imultilib dir
-iprefix file -iquote -isysroot dir -isystem dir -nocpp -nostdinc
-undef

๐Ÿšจ Error and Warning Options ๐Ÿšจ

-Waliasing -Wall -Wampersand -Warray-bounds -Wc-binding-type
-Wcharacter-truncation -Wconversion -Wdo-subscript
-Wfunction-elimination -Wimplicit-interface -Wimplicit-procedure
-Wintrinsic-shadow -Wuse-without-only -Wintrinsics-std
-Wline-truncation -Wno-align-commons -Wno-overwrite-recursive
-Wno-tabs -Wreal-q-constant -Wsurprising -Wunderflow
-Wunused-parameter -Wrealloc-lhs -Wrealloc-lhs-all
-Wfrontend-loop-interchange -Wtarget-lifetime -fmax-errors=n
-fsyntax-only -pedantic -pedantic-errors

๐Ÿ” Debugging Options ๐Ÿ”

-fbacktrace -fdump-fortran-optimized -fdump-fortran-original
-fdebug-aux-vars -fdump-fortran-global -fdump-parse-tree
-ffpe-trap=list -ffpe-summary=list

๐Ÿ“ Directory Options ๐Ÿ“

-Idir  -Jdir -fintrinsic-modules-path dir
-static-libgfortran

โฑ๏ธ Runtime Options โฑ๏ธ

-fconvert=conversion -fmax-subrecord-length=length
-frecord-marker=length -fsign-zero

๐Ÿค Interoperability Options ๐Ÿค

-fc-prototypes -fc-prototypes-external

๐Ÿ› ๏ธ Code Generation Options ๐Ÿ› ๏ธ

-faggressive-function-elimination -fblas-matmul-limit=n
-fbounds-check -ftail-call-workaround -ftail-call-workaround=n
-fcheck-array-temporaries
-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>
-fcoarray=<none|single|lib> -fexternal-blas -ff2c
-ffrontend-loop-interchange -ffrontend-optimize -finit-character=n
-finit-integer=n -finit-local-zero -finit-derived
-finit-logical=<true|false> -finit-real=<zero|inf|-inf|nan|snan>
-finline-matmul-limit=n -finline-arg-packing
-fmax-array-constructor=n -fmax-stack-var-size=n -fno-align-commons
-fno-automatic -fno-protect-parens -fno-underscoring
-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive
-frepack-arrays -fshort-enums -fstack-arrays

๐ŸŽ›๏ธ Options controlling Fortran dialect ๐ŸŽ›๏ธ

The options below are the ones that control the details of the Fortran dialect the compiler accepts ๐Ÿ’–

  • -ffree-form, -ffixed-form โ€” Picks the layout the source file uses. Free form showed up in Fortran 90, while fixed form was the traditional look of older Fortran programs. If you specify neither, the source form gets figured out from the file extension ๐Ÿงš
  • -fall-intrinsics โ€” Causes every intrinsic procedure (including the GNU-specific extensions) to be accepted โœจ This is handy alongside -std=f95 if you want standard-compliance but still want the full set of intrinsics gfortran has. As a consequence, -Wintrinsics-std gets ignored, and no user-defined procedure that shares a name with an intrinsic will be called, unless it's explicitly declared "EXTERNAL" ๐Ÿ™ˆ
  • -fallow-argument-mismatch โ€” Some code calls external procedures with mismatches between the call and the procedure definition, or between different calls ๐Ÿ’€ That code is non-conforming and usually gets flagged as an error. This option downgrades the error to a warning, and the only way to turn that warning off is to disable all warnings with -w. Only a single occurrence per argument gets flagged by this warning. -fallow-argument-mismatch is implied by -std=legacy.
Using this option is strongly discouraged ๐Ÿ˜ญ It's possible to write standard-conforming code that allows different types of arguments by using an explicit interface and TYPE(*).
  • -fallow-invalid-boz โ€” A BOZ literal constant can show up in a limited number of contexts in standard-conforming Fortran. This option downgrades an error condition to a warning, and lets a BOZ literal constant appear where the Fortran standard would otherwise ban it ๐ŸŒˆ
  • -fd-lines-as-code, -fd-lines-as-comments โ€” Turns on special treatment for lines that begin with "d" or "D" in fixed-form sources ๐Ÿฆ‹ With -fd-lines-as-code, they're treated as if the first column held a blank. With -fd-lines-as-comments, they're treated as comment lines.
  • -fdec โ€” DEC compatibility mode ๐Ÿ’… It enables extensions and other features that mimic the default behaviour of older compilers (such as DEC). These features are non-standard and should be avoided at all costs ๐Ÿ’€ For the details on GNU Fortran's version of these extensions, check the full documentation.

Other flags this switch turns on are: -fdollar-ok -fcray-pointer -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints -fdec-static -fdec-math -fdec-include -fdec-blank-format-item -fdec-format-defaults

If -fd-lines-as-code/-fd-lines-as-comments are unset, then -fdec also sets -fd-lines-as-comments โœจ

  • -fdec-char-conversions โ€” Lets you use character literals in assignments and DATA statements for non-character variables ๐ŸŽ€
  • -fdec-structure โ€” Enables DEC STRUCTURE and RECORD, plus UNION, MAP, and dot ('.') as a member separator (on top of '%') ๐Ÿงš This is only here for compatibility. Fortran 90 derived types are the better choice wherever you can use them ๐Ÿ’–
  • -fdec-intrinsic-ints โ€” Enables the B/I/J/K kind variants of existing integer functions (e.g. BIAND, IIAND, JIAND, etc...) โœจ For a complete list of intrinsics, see the full documentation.
  • -fdec-math โ€” Enables legacy math intrinsics like COTAN and degree-valued trigonometric functions (e.g. TAND, ATAND, etc...) so older code stays compatible ๐ŸŒธ
  • -fdec-static โ€” Enables DEC-style STATIC and AUTOMATIC attributes, so you can explicitly specify the storage of variables and other objects ๐Ÿ”ฅ
  • -fdec-include โ€” Enables parsing INCLUDE as a statement in addition to parsing it as an INCLUDE line ๐Ÿฆ‹ When it's parsed as an INCLUDE statement, INCLUDE doesn't have to sit on a single line and can use line continuations.
  • -fdec-format-defaults โ€” Lets the format specifiers F, G and I be used without width specifiers. Default widths get used instead ๐Ÿ“
  • -fdec-blank-format-item โ€” Enables a blank format item at the end of a format specification, i.e. nothing following the final comma ๐Ÿ™ˆ
  • -fdollar-ok โ€” Allows $ as a valid non-first character in a symbol name ๐Ÿ’… Symbols that start with $ are rejected, since it's unclear which implicit typing rules should apply (different vendors implement different rules). Using $ in IMPLICIT statements is rejected too ๐Ÿ’€
  • -fbackslash โ€” Changes how backslashes in string literals are read. Instead of a single backslash character, you get "C-style" escape characters ๐ŸŒˆ These combinations get expanded: \a, \b, \f, \n, \r, \t, \v, \\, and \0, which turn into the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. On top of that, "\x"nn, "\u"nnnn and "\U"nnnnnnnn (where each n is a hexadecimal digit) get translated into the Unicode characters for those code points ๐Ÿคฉ Every other combination of a character preceded by \ stays unexpanded.
  • -fmodule-private โ€” Sets the default accessibility of module entities to PRIVATE ๐Ÿ”’ Use-associated entities won't be accessible unless they're explicitly declared PUBLIC.
  • -ffixed-line-length-n โ€” Sets the column after which characters get ignored in typical fixed-form lines in the source file. Unless -fno-pad-source is used, it also sets the column through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines ๐Ÿ“

Popular values for n include 72 (the standard and the default), 80 (card image), and 132 (corresponding to "extended-source" options in some popular compilers) ๐ŸŽ€ n may also be none, meaning the entire line is meaningful and continued character constants never get implicit spaces appended to fill out the line. -ffixed-line-length-0 means the same thing as -ffixed-line-length-none โœจ

  • -fno-pad-source โ€” By default, fixed-form lines get spaces assumed (as if padded to that length) after the ends of short fixed-form lines ๐Ÿงš That padding doesn't happen if -ffixed-line-length-0, -ffixed-line-length-none, or -fno-pad-source is used. With any of those options, continued character constants never get implicit spaces appended to fill out the line ๐Ÿ’œ
  • -ffree-line-length-n โ€” Okay so this one sets the column where free-form source lines get cut off ๐ŸŽ€. Anything past that column is ignored. The default is 132. Set n to none if you want the entire line to count, no cutoff. And -ffree-line-length-0 is literally the same thing as -ffree-line-length-none โœจ.
  • -fmax-identifier-length=n โ€” Sets the max identifier length ๐Ÿฆ‹. Typical values are 31 for Fortran 95 and 63 for Fortran 2003 and Fortran 2008.
  • -fimplicit-none โ€” No implicit typing allowed, unless you override it with explicit IMPLICIT statements ๐Ÿซถ. It's basically the same as slapping implicit none at the top of every procedure.
  • -fcray-pointer โ€” Turns on the Cray pointer extension, which gives you C-like pointer functionality ๐Ÿงš.
  • -fopenacc โ€” Turns on the OpenACC extensions ๐ŸŒธ. That includes !$acc directives in free form, plus c$acc, *$acc, and !$acc directives in fixed form. It also covers the !$ conditional compilation sentinels in free form, and the c$, *$, and !$ sentinels in fixed form. And when linking, it makes sure the OpenACC runtime library gets linked in too.
  • -fopenmp โ€” Turns on the OpenMP extensions ๐Ÿ’œ. That includes !$omp directives in free form, plus c$omp, *$omp, and !$omp directives in fixed form. It also covers the !$ conditional compilation sentinels in free form, and the c$, *$, and !$ sentinels in fixed form. When linking, it arranges for the OpenMP runtime library to be linked in. And heads up, -fopenmp implies -frecursive ๐Ÿ‘‘.
  • -fno-range-check โ€” Turns off range checking on the results of simplifying constant expressions during compilation ๐Ÿ’€. For example, GNU Fortran will throw an error at compile time when simplifying a = 1. / 0. With this option, there's no error, and a gets the value +Infinity. If an expression evaluates to a value outside the relevant range of ["-HUGE()":HUGE()], it gets replaced by -Inf or +Inf, whichever fits. Similarly, DATA i/Z'FFFFFFFF'/ causes an integer overflow on most systems, but with -fno-range-check the value wraps around and i gets initialized to -1 instead.
  • -fdefault-integer-8 โ€” Sets the default integer and logical types to an 8 byte wide type ๐Ÿ”ฅ. This also affects the kind of integer constants like 42. Unlike -finteger-4-integer-8, it does not promote variables with explicit kind declaration.
  • -fdefault-real-8 โ€” Sets the default real type to an 8 byte wide type โœจ. This also affects the kind of non-double real constants like 1.0. It promotes the default width of DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes if possible. If -fdefault-double-8 is given along with fdefault-real-8, then DOUBLE PRECISION and double real constants are not promoted. Unlike -freal-4-real-8, fdefault-real-8 does not promote variables with explicit kind declarations.
  • -fdefault-real-10 โ€” Sets the default real type to a 10 byte wide type ๐ŸŒˆ. This also affects the kind of non-double real constants like 1.0. It promotes the default width of DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes if possible. If -fdefault-double-8 is given along with fdefault-real-10, then DOUBLE PRECISION and double real constants are not promoted. Unlike -freal-4-real-10, fdefault-real-10 does not promote variables with explicit kind declarations.
  • -fdefault-real-16 โ€” Sets the default real type to a 16 byte wide type ๐Ÿ’–. This also affects the kind of non-double real constants like 1.0. It promotes the default width of DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes if possible. If -fdefault-double-8 is given along with fdefault-real-16, then DOUBLE PRECISION and double real constants are not promoted. Unlike -freal-4-real-16, fdefault-real-16 does not promote variables with explicit kind declarations.
  • -fdefault-double-8 โ€” Sets the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type ๐Ÿ“. If that's already the default, it does nothing. This option stops -fdefault-real-8, -fdefault-real-10, and -fdefault-real-16 from promoting DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes.
  • -finteger-4-integer-8 โ€” Promotes all INTEGER(KIND=4) entities to INTEGER(KIND=8) entities ๐Ÿฆ‹. If KIND=8 is unavailable, an error gets issued. Use this one with care, because it may not be suitable for your codes. Areas of possible concern include calls to external procedures, alignment in EQUIVALENCE and/or COMMON, generic interfaces, BOZ literal constant conversion, and I/O. Inspecting the intermediate representation of the translated Fortran code, produced by -fdump-tree-original, is suggested.
  • -freal-4-real-8, -freal-4-real-10, -freal-4-real-16, -freal-8-real-4, -freal-8-real-10, -freal-8-real-16 โ€” Promotes all REAL(KIND=M) entities to REAL(KIND=N) entities ๐Ÿ’…. If REAL(KIND=N) is unavailable, an error gets issued. The -freal-4- flags also affect the default real kind, and the -freal-8- flags also affect the double-precision real kind. All other real-kind types are unaffected. The promotion also applies to real literal constants of default and double-precision kind, with a specified kind number of 4 or 8 respectively. However, -fdefault-real-8, -fdefault-real-10, -fdefault-real-10, and -fdefault-double-8 take precedence for the default and double-precision real kinds, both for real literal constants and for declarations without a kind number. Note that for REAL(KIND=KIND(1.0)), the literal may get promoted and then the result may get promoted again.

These options should be used with care and may not be suitable for your codes ๐Ÿ˜ญ. Areas of possible concern include calls to external procedures, alignment in EQUIVALENCE and/or COMMON, generic interfaces, BOZ literal constant conversion, I/O, and calls to intrinsic procedures when passing a value to the kind= dummy argument. Inspecting the intermediate representation of the translated Fortran code, produced by -fdump-fortran-original or -fdump-tree-original, is suggested.

  • -std=std โ€” Specifies the standard your program is expected to conform to ๐Ÿ“œ. It may be one of f95, f2003, f2008, f2018, gnu, or legacy. The default is gnu, which is a superset of the latest Fortran standard that includes all of the extensions GNU Fortran supports, although warnings get given for obsolete extensions not recommended for new code. The legacy value is equivalent but without the warnings for obsolete extensions, and it may be useful for old non-standard programs. The f95, f2003, f2008, and f2018 values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008, and Fortran 2018 standards respectively. Errors get given for all extensions beyond the relevant language standard, and warnings get given for the Fortran 77 features that are permitted but obsolescent in later standards.
The deprecated option -std=f2008ts acts as an alias for -std=f2018. It's only there for backwards compatibility with earlier gfortran versions, so please don't use it any more ๐Ÿ™ˆ.
  • -ftest-forall-temp โ€” Boosts test coverage by forcing most forall assignments to use a temporary ๐Ÿงช.

โœจ Enable and customize preprocessing โœจ

Preprocessor related options ๐ŸŒท. See section Preprocessing and conditional compilation for more detailed information on preprocessing in gfortran.

  • -cpp, -nocpp โ€” -cpp turns on preprocessing ๐Ÿ’–. The preprocessor gets invoked automatically if the file extension is .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03, or .F08. Use this flag to manually enable preprocessing of any kind of Fortran file.

To disable preprocessing of files with any of the extensions listed above, use the negative form: -nocpp ๐Ÿ™….

The preprocessor runs in traditional mode. Any restrictions of the file format, especially the limits on line length, apply to the preprocessed output as well, so it might be advisable to use the -ffree-line-length-none or -ffixed-line-length-none options ๐Ÿฆ‹.

  • -dM โ€” Instead of the normal output, this generates a list of #define directives for all the macros defined during the execution of the preprocessor, including predefined macros ๐Ÿ”. It's a way of finding out what's predefined in your version of the preprocessor. Assuming you have no file foo.f90, the command:
touch foo.f90; gfortran -cpp -E -dM foo.f90

will show all the predefined macros.

  • -dD โ€” Like -dM, except in two respects: it does not include the predefined macros, and it outputs both the #define directives and the result of preprocessing ๐Ÿง. Both kinds of output go to the standard output file.
  • -dN โ€” Like -dD, but emits only the macro names, not their expansions ๐Ÿซง.
  • -dU โ€” Like dD, except only macros that are expanded, or whose definedness is tested in preprocessor directives, are output ๐ŸŒธ. The output is delayed until the use or test of the macro, and #undef directives are also output for macros tested but undefined at the time.
  • -dI โ€” Outputs #include directives in addition to the result of preprocessing ๐Ÿ“‚.
  • -fworking-directory โ€” Enables generation of linemarkers in the preprocessor output that let the compiler know the current working directory at the time of preprocessing ๐Ÿ“. When this option is enabled, the preprocessor emits, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC will use this directory, when it's present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats. This option is implicitly enabled if debugging information is enabled, but you can inhibit it with the negated form -fno-working-directory. If the -P flag is present on the command line, this option has no effect, since no #line directives are emitted whatsoever.
  • -idirafter dir โ€” Searches dir for include files, but does it after all the directories specified with -I and the standard system directories have been exhausted ๐Ÿงš. dir is treated as a system include directory. If dir begins with =, then the = gets replaced by the sysroot prefix; see --sysroot and -isysroot ๐Ÿ‘‘.
  • -imultilib dir: okay so this one lets you use dir as a subdirectory of the directory that holds the target-specific C++ headers ๐Ÿฆ‹
  • -iprefix prefix: sets prefix as the prefix for later -iwithprefix options โœจ If the prefix is a directory, make sure you include the final /, bestie ๐ŸŽ€
  • -isysroot dir: this is giving --sysroot vibes, but it only applies to header files ๐Ÿ“ Check out --sysroot for the full tea.
  • -iquote dir: searches dir only for headers requested with #include "file". They are NOT searched for #include <file> ๐Ÿ™ˆ This happens before all the -I directories and before the standard system directories. If dir starts with =, that = gets swapped out for the sysroot prefix. See --sysroot and -isysroot.
  • -isystem dir: searches dir for headers after all the -I directories but before the standard system directories ๐Ÿ’œ It gets marked as a system directory, so it gets the same special treatment as the standard ones. If dir starts with =, the = gets replaced by the sysroot prefix. See --sysroot and -isysroot.
  • -nostdinc: don't search the standard system directories for headers ๐Ÿšซ Only the directories you gave with -I options (plus the directory of the current file, if it applies) get searched.
  • -undef: don't predefine any system-specific or GCC-specific macros ๐Ÿงš The standard predefined macros stay defined, though.
  • -Apredicate=answer: makes an assertion with the predicate predicate and the answer answer ๐Ÿ’… This is the preferred form over the older -A predicate(answer). That one still works, but this one doesn't use shell special characters, so it's way less drama.
  • -A-predicate=answer: cancels an assertion with the predicate predicate and the answer answer ๐Ÿซถ
  • -C: don't throw away comments! All comments get passed through to the output file, except comments inside processed directives. Those get deleted along with the directive ๐Ÿ˜ญ

Heads up, you should be prepared for side effects with -C. It makes the preprocessor treat comments as tokens in their own right ๐Ÿ’€ For example, comments sitting at the start of what would be a directive line turn that line into an ordinary source line, since the first token on the line is no longer a #.

Warning: this currently handles C-Style comments only. The preprocessor does not yet recognize Fortran-style comments.
  • -CC: don't discard comments, even during macro expansion ๐ŸŒˆ This is like -C, except comments contained within macros also get passed through to the output file wherever the macro is expanded.

On top of the side effects of -C, the -CC option converts all C++-style comments inside a macro into C-style comments. This stops a later use of that macro from accidentally commenting out the rest of the source line ๐Ÿ™…โ€โ™€๏ธ -CC is generally used to support lint comments.

Warning: this currently handles C- and C++-Style comments only. The preprocessor does not yet recognize Fortran-style comments.
  • -Dname: predefines name as a macro, with the definition 1 โญ
  • -Dname=definition: the contents of definition get tokenized and processed as if they appeared during translation phase three in a #define directive ๐ŸŒธ In particular, the definition gets cut off by embedded newline characters.

If you're invoking the preprocessor from a shell or shell-like program, you may need the shell's quoting syntax to protect characters like spaces, since they have a meaning in shell syntax ๐ŸŽ€

If you want to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if there is one). Parentheses mean something to most shells, so you'll need to quote the option. With sh and csh, "-D'name(args...)=definition'" works ๐Ÿง 

-D and -U options are processed in the order they're given on the command line. All -imacros file and -include file options get processed after all -D and -U options ๐Ÿ”ฅ

  • -H: prints the name of each header file used, along with the other normal activities ๐Ÿฆ‹ Each name is indented to show how deep it sits in the #include stack.
  • -P: stops the preprocessor from generating linemarkers in its output ๐Ÿƒ This might be useful when you run the preprocessor on something that isn't C code and will get sent to a program that could get confused by the linemarkers.
  • -Uname: cancels any previous definition of name, whether it was built in or provided with a -D option ๐Ÿ‘‘

โœจ Options to request or suppress errors and warnings โœจ

Errors are diagnostic messages that report the GNU Fortran compiler can't compile the relevant piece of source code ๐Ÿ’€ The compiler keeps going so it can report more errors and help you debug, but it won't produce any compiled output.

Warnings are diagnostic messages about constructions that aren't inherently erroneous, but are risky or suggest there's likely a bug in the program ๐Ÿ‘€ Unless -Werror is specified, they don't stop the program from compiling.

You can request lots of specific warnings with options beginning -W. For example, -Wimplicit requests warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- that turns warnings off, like -Wno-implicit. This manual lists only one of the two forms, whichever one is not the default ๐Ÿ’…

These options control the amount and kinds of errors and warnings GNU Fortran produces:

  • -fmax-errors=n: limits the maximum number of error messages to n ๐Ÿ›‘ Once it hits that, GNU Fortran bails out rather than trying to keep processing the source code. If n is 0, there is no limit on the number of error messages produced.
  • -fsyntax-only: checks the code for syntax errors without actually compiling it โœจ This will generate module files for each module present in the code, but no other output file.
  • -Wpedantic, -pedantic: issues warnings for uses of extensions to Fortran ๐Ÿค“ -pedantic also applies to C-language constructs where they show up in GNU Fortran source files, like using \e in a character constant within a directive such as #include.

Valid Fortran programs should compile properly with or without this option. Without it, though, certain GNU extensions and traditional Fortran features are supported too. With this option, many of them get rejected ๐Ÿ™…โ€โ™€๏ธ

Some users try to use -pedantic to check programs for conformance. They soon find it doesn't quite do what they want: it finds some nonstandard practices, but not all ๐Ÿ˜ญ Improvements to GNU Fortran in this area are welcome, though.

This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018.

  • -pedantic-errors: like -pedantic, except errors are produced rather than warnings ๐Ÿšจ
  • -Wall: enables commonly used warning options for usage we recommend avoiding, and that we believe are easy to avoid ๐ŸŽ€ This currently includes -Waliasing, -Wampersand, -Wconversion, -Wsurprising, -Wc-binding-type, -Wintrinsics-std, -Wtabs, -Wintrinsic-shadow, -Wline-truncation, -Wtarget-lifetime, -Winteger-division, -Wreal-q-constant, -Wunused and -Wundefined-do-loop.
  • -Waliasing: warns about possible aliasing of dummy arguments ๐Ÿ‘ฏ Specifically, it warns if the same actual argument is associated with a dummy argument with INTENT(IN) and a dummy argument with INTENT(OUT) in a call with an explicit interface.

The following example will trigger the warning:

interface
  subroutine bar(a,b)
    integer, intent(in) :: a
    integer, intent(out) :: b
  end subroutine
end interface
integer :: a

call bar(a,a)
  • -Wampersand: warns about a missing ampersand in continued character constants ๐Ÿงต The warning is given with -Wampersand, -pedantic, -std=f95, -std=f2003, -std=f2008 and -std=f2018. Note: with no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that started the continuation.
  • -Warray-temporaries: warns about array temporaries generated by the compiler ๐Ÿ—‚๏ธ The info from this warning is sometimes useful for optimization, so you can avoid those temporaries.
  • -Wc-binding-type: warns if a variable might not be C interoperable ๐Ÿ”— In particular, it warns if the variable was declared using an intrinsic type with the default kind, instead of using a kind parameter defined for C interoperability in the intrinsic ISO_C_Binding module. This option is implied by -Wall.
  • -Wcharacter-truncation: warns when a character assignment will truncate the assigned string โœ‚๏ธ
  • -Wline-truncation: warns when a source code line will be truncated ๐Ÿ“ This option is implied by -Wall. For free-form source code, the default is -Werror=line-truncation, so truncations get reported as errors.
  • -Wconversion: warns about implicit conversions that are likely to change the value of the expression after conversion ๐Ÿ”„ Implied by -Wall.
  • -Wconversion-extra: warns about implicit conversions between different types and kinds ๐ŸŒ€ This option does not imply -Wconversion.
  • -Wextra: enables some warning options for usages of language features that may be problematic ๐Ÿง This currently includes -Wcompare-reals, -Wunused-parameter and -Wdo-subscript.
  • -Wfrontend-loop-interchange: warns when -ffrontend-loop-interchange is used to perform loop interchanges ๐Ÿ”
  • -Wimplicit-interface: warns if a procedure is called without an explicit interface ๐Ÿ“ž Note this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units.
  • -Wimplicit-procedure: warns if a procedure is called that has neither an explicit interface nor has been declared as EXTERNAL ๐Ÿซฃ
  • -Winteger-division: warns if a constant integer division truncates its result ๐Ÿ• As an example, 3/5 evaluates to 0.
  • -Wintrinsics-std โ€” โœจ Heads up, bestie! If gfortran finds a procedure named like an intrinsic that isn't available in the standard you picked (with -std), it'll warn you and treat it as an EXTERNAL procedure instead ๐Ÿ™ˆ. If you never want that to happen, -fall-intrinsics always links to the intrinsic, no matter which standard you chose ๐Ÿ’…
  • -Wno-overwrite-recursive โ€” ๐ŸŒธ Skips the warning when -fno-automatic is used with -frecursive. Recursion gets broken if the relevant local variables don't have the AUTOMATIC attribute explicitly declared. Use this when you know recursion isn't broken and you just want the noise gone. It's super useful for build setups that use -Werror ๐Ÿซถ
  • -Wreal-q-constant โ€” ๐Ÿฆ‹ Warns if a real literal constant has a q exponent letter.
  • -Wsurprising โ€” ๐Ÿ‘€ Warns about "suspicious" code. It's technically legal, but it usually means someone made a mistake. Right now it fires in these situations:
    • An INTEGER SELECT construct has a CASE that can never be matched, because its lower value is greater than its upper value.
    • A LOGICAL SELECT construct has three CASE statements.
    • A TRANSFER specifies a source that's shorter than the destination.
    • The type of a function result is declared more than once with the same type. If -pedantic or standard-conforming mode is on, this is an error ๐Ÿ’€
    • A CHARACTER variable is declared with a negative length.
  • -Wtabs โ€” ๐Ÿ“ Tabs are accepted as whitespace by default, but they aren't members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported. -Wtabs makes gfortran warn whenever it spots a tab. It's active for -pedantic, -std=f95, -std=f2003, -std=f2008, -std=f2018 and -Wall too โœจ
  • -Wundefined-do-loop โ€” ๐ŸŒ€ Warns if a DO loop with step either 1 or -1 hits an underflow or overflow while its induction variable is iterating. This one's implied by -Wall.
  • -Wunderflow โ€” ๐Ÿ“‰ Warns when numerical constant expressions are encountered that give an UNDERFLOW during compilation. It's on by default, so you get it for free ๐ŸŽ€
  • -Wintrinsic-shadow โ€” ๐Ÿ•ต๏ธ Warns if a user-defined procedure or module procedure has the same name as an intrinsic. You might need an explicit interface, or an EXTERNAL or INTRINSIC declaration, so later calls resolve to the procedure you actually wanted. Implied by -Wall.
  • -Wuse-without-only โ€” ๐Ÿซฃ Warns if a USE statement has no ONLY qualifier, because then it quietly and implicitly imports all public entities of the used module.
  • -Wunused-dummy-argument โ€” ๐Ÿงน Warns about unused dummy arguments. Implied by -Wall.
  • -Wunused-parameter โ€” ๐Ÿ”„ Plot twist: this one is not the same as gcc's version! gfortran's implementation doesn't warn about unused dummy arguments (that's -Wunused-dummy-argument). Instead, it warns about unused PARAMETER values. It's implied by -Wextra if -Wunused or -Wall is also used.
  • -Walign-commons โ€” ๐Ÿงฉ By default, gfortran warns about any time variables get padded for proper alignment inside a COMMON block. You can silence it with -Wno-align-commons. See also -falign-commons.
  • -Wfunction-elimination โ€” ๐Ÿ—‘๏ธ Warns if any calls to impure functions get eliminated by the optimizations enabled by -ffrontend-optimize. Implied by -Wextra.
  • -Wrealloc-lhs โ€” โ™ป๏ธ Warns when the compiler might insert code for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature may hurt performance. If the array is already allocated with the correct shape, try a whole-array array-spec like (:,:,:) on the left-hand side to skip the reallocation check. The warning can show up even when the compiler would optimize those checks away anyway, like when the right-hand side has the same variable multiplied by a scalar. See also -frealloc-lhs.
  • -Wrealloc-lhs-all โ€” ๐Ÿ’ซ Warns when the compiler inserts allocation or reallocation code for any allocatable variable, including scalars and derived types.
  • -Wcompare-reals โ€” โš–๏ธ Warns when you compare real or complex types for equality or inequality. Implied by -Wextra.
  • -Wtarget-lifetime โ€” โณ Warns if the pointer in a pointer assignment might outlive its target. Implied by -Wall.
  • -Wzerotrip โ€” 0๏ธโƒฃ Warns if a DO loop is known at compile time to execute zero times. Implied by -Wall.
  • -Wdo-subscript โ€” ๐ŸŽฏ Warns if an array subscript inside a DO loop could lead to an out-of-bounds access, even if the compiler can't prove the statement actually runs. Something like this:
real a(3)
do i=1,4
  if (condition(i)) then
    a(i) = 1.2
  end if
end do

Implied by -Wextra.

  • -Werror โ€” ๐Ÿšจ Turns all warnings into errors, so no warning gets to slide.

Some of these have no effect when compiling programs written in Fortran.


๐Ÿ” Options for debugging your program or GNU Fortran ๐Ÿ”

GNU Fortran has a bunch of special options for debugging either your program or the GNU Fortran compiler itself ๐Ÿงš

  • -fdump-fortran-original โ€” ๐ŸŒฑ Outputs the internal parse tree after the source program has been translated into internal representation. It's mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may also cause internal compiler errors for features that were only recently added.
  • -fdump-fortran-optimized โ€” ๐Ÿงช Outputs the parse tree after front-end optimization. Mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may also cause internal compiler errors for features that were only recently added.
  • -fdump-parse-tree โ€” ๐Ÿ—‚๏ธ Outputs the internal parse tree after the source program has been translated into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may cause internal compiler errors for features that were only recently added. This option is deprecated, so use -fdump-fortran-original instead ๐Ÿ™…
  • -fdebug-aux-vars โ€” ๐Ÿ”Ž Renames the internal variables created by the gfortran front end and makes them accessible to a debugger. Their names start with upper-case letters followed by an underscore. It's handy for debugging the compiler's code generation together with -fdump-tree-original, and for debugging the executable program by using -g or -ggdb3.
  • -fdump-fortran-global โ€” ๐ŸŒ Outputs a list of the global identifiers after translating into middle-end representation. Mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may also cause internal compiler errors for features that were only recently added.
  • -ffpe-trap=list โ€” ๐Ÿ’ฅ Specifies a list of floating point exception traps to enable. On most systems, if a floating point exception happens and its trap is enabled, a SIGFPE signal is sent and the program gets aborted, producing a core file that's useful for debugging. list is a (possibly empty) comma-separated list of these exceptions:
    • invalid (invalid floating point operation, such as SQRT(-1.0))
    • zero (division by zero)
    • overflow (overflow in a floating point operation)
    • underflow (underflow in a floating point operation)
    • inexact (loss of precision during operation)
    • denormal (operation performed on a denormal value)

The first five correspond to the five IEEE 754 exceptions. The last one, denormal, isn't part of the IEEE 754 standard, but it's available on some common architectures like x86.

The first three exceptions (invalid, zero, and overflow) often point to serious errors. Unless your program has a plan for dealing with them, turning on traps for those three is probably a good idea ๐Ÿ›ก๏ธ

If you use -ffpe-trap more than once on the command line, the lists get joined. So -ffpe-trap=list1 followed by -ffpe-trap=list2 is the same as -ffpe-trap=list1,list2.

Once an exception is enabled, it can't be disabled. There's no negative form, so choose wisely! ๐Ÿ™…โ€โ™€๏ธ

Many, if not most, floating point operations lose some precision due to rounding, so -ffpe-trap=inexact is likely to be uninteresting in practice ๐Ÿ˜ด

By default, no exception traps are enabled.

  • -ffpe-summary=list โ€” ๐Ÿ“‹ Specifies a list of floating-point exceptions whose flag status gets printed to ERROR_UNIT when you invoke STOP or ERROR STOP. list can be none, all, or a comma-separated list of these exceptions: invalid, zero, overflow, underflow, inexact and denormal. (See -ffpe-trap for what each one means.)

If you use this option more than once on the command line, only the last one counts. By default, a summary is shown for all exceptions except inexact โœจ

  • -fno-backtrace โ€” ๐Ÿ™ˆ When a serious runtime error or a deadly signal happens (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals that have the action core), the Fortran runtime library tries to print a backtrace of the error. -fno-backtrace turns that backtrace generation off. This option only has an effect when compiling the Fortran main program ๐ŸŽ€

These options affect how GNU Fortran searches for files specified by the INCLUDE directive, and where it searches for previously compiled modules ๐Ÿ—บ๏ธ

They also affect the search paths used by cpp when it preprocesses Fortran source.

  • -Idir โ€” ๐Ÿงญ These affect how the INCLUDE directive gets interpreted, and also the #include directive of the cpp preprocessor.

Also note that -I and INCLUDE act pretty much the same way -I does with #include in the cpp preprocessor ๐Ÿงš, when it comes to looking for header.gcc files and other stuff like that.

This path is also used to search for .mod files when previously compiled modules are needed by a USE statement ๐Ÿ“ฆ

  • -Jdir โ€” This tells the compiler where to put .mod files for compiled modules ๐Ÿ—‚๏ธ It also gets added to the list of directories that a USE statement searches. The default is the current directory.
  • -fintrinsic-modules-path dir โ€” Use this if your pre-compiled intrinsic modules aren't in the default spot the compiler expects ๐Ÿ”

โœจ Influencing the linking step โœจ

These options only matter when the compiler links object files into an executable output file ๐Ÿ”— If the compiler isn't doing a link step, they're totally meaningless ๐Ÿ™ƒ

  • -static-libgfortran โ€” On systems that ship libgfortran as both a shared and a static library, this forces the static version ๐Ÿ’ช If no shared version of libgfortran got built when the compiler was configured, this option does nothing.

๐ŸŒธ Influencing runtime behavior ๐ŸŒธ

These options change how programs compiled with GNU Fortran behave at runtime ๐ŸŽ€

  • -fconvert=conversion โ€” This sets how data is represented in unformatted files ๐Ÿ’… The valid values for conversion are:
    • native โ€” the default
    • swap โ€” swap between big- and little-endian
    • big-endian โ€” use big-endian representation for unformatted files
    • little-endian โ€” use little-endian representation for unformatted files

This option only has an effect when it's used in the main program ๐Ÿ‘‘ The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable both override the default you set with -fconvert.

  • -frecord-marker=length โ€” This sets the length of record markers for unformatted files ๐Ÿฆ‹ The valid values for length are 4 and 8, and the default is 4. Heads up, this is different from older gfortran versions, which defaulted to 8 on most systems. If you want to read or write files that are compatible with earlier gfortran versions, use -frecord-marker=8 ๐Ÿซถ
  • -fmax-subrecord-length=length โ€” This sets the max length for a subrecord ๐Ÿง The biggest value you can use for length is 2147483639, which is also the default. It's only really useful for the gfortran testsuite, so don't stress about it ๐Ÿ’€
  • -fsign-zero โ€” When this is enabled, floating point numbers with a value of zero but the sign bit set get written as negative numbers in formatted output, and they're treated as negative in the SIGN intrinsic โœจ -fno-sign-zero goes the other way: it doesn't print the negative sign of zero values (or values rounded to zero for I/O), and it counts zero as a positive number in the SIGN intrinsic, for compatibility with Fortran 77 ๐ŸŒˆ The default is -fsign-zero.

๐Ÿงถ Options for code generation conventions ๐Ÿงถ

These machine-independent options control the interface conventions used in code generation ๐Ÿง 

Most of them come in positive and negative forms, where the negative form of -ffoo is -fno-foo ๐Ÿ’œ Below, only one form is listed, the one that isn't the default. You can figure out the other form by removing no- or adding it.

  • -fno-automatic โ€” This treats each program unit (except those marked as RECURSIVE) like the SAVE statement was specified for every local variable and array referenced in it ๐Ÿซง It doesn't affect common blocks. Some Fortran compilers call this option -static or -save. The default, which is -fautomatic, uses the stack for local variables smaller than the value given by -fmax-stack-var-size. If you want no static memory at all, use the option -frecursive.

Local variables or arrays with an explicit SAVE attribute get silently ignored unless you add the -pedantic option ๐Ÿ™ˆ

  • -ff2c โ€” This generates code that's designed to be compatible with code made by g77 and f2c ๐Ÿ“

The calling conventions g77 uses (originally from f2c) make functions that return default REAL actually return the C type double. Functions that return COMPLEX return their values through an extra argument in the calling sequence, which points to where the return value should be stored. With the default GNU calling conventions, those functions just return their results the way GNU C would: default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. On top of that, this option implies -fsecond-underscore, unless you explicitly ask for -fno-second-underscore.

This doesn't affect code that interfaces with the libgfortran library.

Caution: It's not a good idea to mix Fortran code compiled with -ff2c with code compiled with the default -fno-f2c calling conventions. Calling COMPLEX or default REAL functions between program parts that were compiled with different calling conventions will break at execution time ๐Ÿ’€
Caution: This will break code that passes intrinsic functions of type default REAL or COMPLEX as actual arguments, because the library implementations use the -fno-f2c calling conventions ๐Ÿ˜ญ
  • -fno-underscoring โ€” This stops GNU Fortran from changing the names of entities in your Fortran source file by adding underscores to them ๐Ÿ™…โ€โ™€๏ธ

With -funderscoring in effect, GNU Fortran adds one underscore to external names that don't have any underscores already. It does this so the code plays nicely with lots of UNIX Fortran compilers ๐Ÿค

Caution: GNU Fortran's default behavior is incompatible with f2c and g77. If you want object files made by GNU Fortran to be compatible with object code made by those tools, please use the -ff2c option ๐Ÿซถ

Using -fno-underscoring isn't recommended unless you're experimenting with stuff like fitting GNU Fortran into existing system environments (think existing libraries, tools, and so on) ๐Ÿงช

Here's an example. Say j() and max_count() are external functions, while my_var and lvar are local variables. With -funderscoring, a statement like this:

I = J() + MAX_COUNT (MY_VAR, LVAR)

gets implemented as something akin to:

i = j_() + max_count__(&my_var__, &lvar);

With -fno-underscoring, that same statement gets implemented as:

i = j() + max_count(&my_var, &lvar);

Using -fno-underscoring lets you call user-defined names directly while debugging and when you're interfacing GNU Fortran code with other languages ๐ŸŒท

Just because the names match doesn't mean the interface GNU Fortran uses for an external name matches the interface another language uses for that same name ๐Ÿค” Getting code from GNU Fortran to link with code from some other compiler (using this or any other method) can be just a small part of the whole solution. Getting both compilers' output to agree on things other than naming can take a ton of effort, and unlike naming disagreements, linkers normally can't detect disagreements in those other areas.

Also, with -fno-underscoring, the lack of appended underscores makes it very real that a user-defined external name could clash with a name in a system library. That can make unresolved-reference bugs really hard to find. They might happen at program run time and only show up as buggy behavior while the program runs ๐Ÿ˜ต

In future versions of GNU Fortran, the plan is to improve naming and linking so debugging always uses the names as they appear in the source, even if the linker sees mangled names that stop accidental linking between procedures with incompatible interfaces โœจ

  • -fsecond-underscore โ€” By default, GNU Fortran appends an underscore to external names ๐Ÿ’… If you use this option, GNU Fortran appends two underscores to names that already have underscores, and one underscore to external names that don't. It also appends two underscores to internal names that have underscores, so they don't collide with external names.

This option has no effect if -fno-underscoring is in effect, and it's implied by the -ff2c option.

Without this option, an external name like MAX_COUNT gets implemented as a reference to the link-time external symbol max_count_. With this option, the same name becomes a reference to max_count__ instead. That's required for compatibility with g77 and f2c, and -ff2c implies it ๐Ÿ”ฅ

  • -fcoarray=<keyword> โ€” This controls coarray support, and you pick one of these keywords ๐Ÿงš
    • none โ€” Disables coarray support. Using coarray declarations and image-control statements will give you a compile-time error. (Default)
    • single โ€” Single-image mode, which means num_images() is always one ๐ŸŒฑ
    • lib โ€” Library-based coarray parallelization. A suitable GNU Fortran coarray library needs to be linked in ๐Ÿ“š
  • -fcheck=<keyword> โ€” This turns on the generation of run-time checks. The argument is a comma-delimited list of the keywords below โœ… Putting no- in front of a check turns it off, if an earlier specification turned it on.
    • all โ€” Enables all run-time tests of -fcheck ๐ŸŒˆ
    • array-temps โ€” Pings you at run time whenever passing an actual argument forced a temporary array to get made ๐Ÿงพ That info can be really handy for optimization, since you can use it to avoid those temporaries.
      • Heads up: this warning only prints once per location.
    • bits โ€” Turns on run-time checks for invalid arguments to the bit manipulation intrinsics ๐Ÿงฎ
    • bounds โ€” Turns on run-time checks for array subscripts against the declared minimum and maximum values ๐Ÿ“ It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds, and makes sure all string lengths match for character array constructors that don't have an explicit typespec.
      • Some checks need -fcheck=bounds to be set when the main program is compiled ๐Ÿ‘‘
      • Note: in the future this might also include other forms of checking, like checking substring references ๐Ÿ”ฎ
    • do โ€” Turns on run-time checks for invalid modification of loop iteration variables ๐Ÿ”
  • mem โ€” ๐Ÿง  turns on run-time checks for memory allocation. Heads up, bestie: this doesn't cover explicit allocations made with the ALLOCATE statement, because those are always checked anyway ๐Ÿ’…
  • pointer โ€” ๐Ÿ‘‰ turns on run-time checks for pointers and allocatables โœจ
  • recursion โ€” ๐ŸŒ€ turns on run-time checks for recursively called subroutines and functions that aren't marked as recursive. See also -frecursive ๐Ÿฆ‹ Note: this check doesn't work for OpenMP programs, and it gets switched off if you use it together with both -frecursive and -fopenmp ๐Ÿ™ˆ

Example time ๐ŸŽ€ Say you've got a file called foo.f90, and you run:

gfortran -fcheck=all,no-array-temps foo.f90

That compiles the file with all the checks enabled as described above, except the warnings for generated array temporaries ๐Ÿ’–

  • -fbounds-check โ€” ๐Ÿ—‘๏ธ old-school name, and it's just a deprecated alias for -fcheck=bounds.
  • -ftail-call-workaround, -ftail-call-workaround=n โ€” ๐Ÿฉน okay so some C interfaces to Fortran code are rude and skip the hidden character length arguments as described in. That can cause crashes, because pushing arguments for tail calls can overflow the stack ๐Ÿ˜ญ

This option is a band-aid for existing binary packages. It turns off tail call optimization for gfortran procedures with character arguments:

  • With -ftail-call-workaround=2, tail call optimization is disabled in all gfortran procedures with character arguments.
  • With -ftail-call-workaround=1 or plain -ftail-call-workaround, it's only disabled in gfortran procedures with character arguments that call implicitly prototyped procedures.
Caution: using this option can lead to problems, including crashes due to insufficient stack space ๐Ÿ’€
It is very strongly recommended to fix the code in question ๐Ÿซถ The -fc-prototypes-external option can generate prototypes that conform to gfortran's ABI, so you can include them in your source code.
Support for this option will likely be withdrawn in a future release of gfortran ๐Ÿ‘‹

To turn it off, use -fno-tail-call-workaround or the equivalent -ftail-call-workaround=0. The current default is -ftail-call-workaround, but that's going to change in future releases ๐ŸŒธ

  • -fcheck-array-temporaries โ€” ๐Ÿ—‘๏ธ deprecated alias for -fcheck=array-temps.
  • -fmax-array-constructor=n โ€” ๐Ÿ“ raises the upper limit allowed in array constructors. The code below needs this option so it can expand the array at compile time ๐Ÿ‘‘
        program test
        implicit none
        integer j
        integer, parameter :: n = 100000
        integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
        print '(10(I0,1X))', i
        end program test
Caution: this option can lead to long compile times and excessively large object files ๐Ÿ’€

The default value for n is 65535.

  • -fmax-stack-var-size=n โ€” ๐Ÿฅž sets the size in bytes of the biggest array that gets put on the stack. If an array goes over that size, static memory is used instead (except in procedures marked as RECURSIVE). To allow recursive procedures that don't have a RECURSIVE attribute, or for parallel programs, use -frecursive. To never use the stack, use -fno-automatic ๐Ÿงš

This option currently only affects local arrays declared with constant bounds, and it may not apply to all character variables. Future versions of GNU Fortran may improve this behaviour โœจ

The default value for n is 65536.

  • -fstack-arrays โ€” ๐Ÿฅก this puts all arrays of unknown size and all array temporaries onto stack memory. If your program uses really big local arrays, you might have to extend your runtime stack memory limits on some operating systems ๐Ÿ˜… This flag is enabled by default at optimization level -Ofast, unless -fmax-stack-var-size is specified.
  • -fpack-derived โ€” ๐Ÿ“ฆ tells GNU Fortran to pack derived type members as closely together as possible. Code compiled with this option is likely to be incompatible with code compiled without it, and it may run slower ๐Ÿข
  • -frepack-arrays โ€” ๐Ÿงน sometimes GNU Fortran passes assumed shape array sections through a descriptor that describes a noncontiguous chunk of memory. This option adds code to the function prologue that repacks the data into a contiguous block at runtime ๐Ÿงฉ

This should make array accesses faster. However, it can add significant overhead to the function call, especially when the passed data is noncontiguous ๐Ÿ˜ฌ

  • -fshort-enums โ€” ๐Ÿ”ข this one's for interoperability with C code that was compiled with -fshort-enums. GNU Fortran will pick the smallest INTEGER kind that a given enumerator set fits in, and give all of its enumerators that kind ๐Ÿ’œ
  • -finline-arg-packing โ€” ๐Ÿ“ฅ when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size argument, or to a procedure without an explicit interface, the argument might have to be packed (put into contiguous memory). Here's an example, the call to foo in:
        subroutine foo(a)
           real, dimension(*) :: a
        end subroutine foo
        subroutine bar(b)
           real, dimension(:) :: b
           call foo(b)
        end subroutine bar

When -finline-arg-packing is in effect, that packing is done by inline code. That allows for more optimization, but the code gets bigger ๐Ÿ“ˆ

-finline-arg-packing is implied by any of the -O options, except when optimizing for size with -Os. If the code has a very large number of arguments that need packing, the code size and compile time can get excessive. If that happens, it might be better to disable this option ๐Ÿ™ˆ You can find instances of packing by using -Warray-temporaries.

  • -fexternal-blas โ€” ๐Ÿงฎ makes gfortran call BLAS functions for some matrix operations like MATMUL, instead of using its own algorithms, as long as the matrices involved are larger than a given limit (see -fblas-matmul-limit). This can be a win if an optimized vendor BLAS library is available ๐Ÿ”ฅ The BLAS library has to be specified at link time.
  • -fblas-matmul-limit=n โ€” ๐Ÿ“ only matters when -fexternal-blas is in effect. Matrix multiplications with a size larger than (or equal to) n are done by calls to BLAS functions, and the rest are handled by gfortran's internal algorithms. If the matrices aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices ๐Ÿฆ‹

The default value for n is 30.

  • -finline-matmul-limit=n โ€” ๐Ÿช„ when front-end optimization is active, some calls to the MATMUL intrinsic function get inlined. This can increase code size if the size of the matrix can't be figured out at compile time, since code for both cases gets generated. Setting -finline-matmul-limit=0 turns off inlining in all cases. Setting it to a value of n produces inline code for matrices up to size n. If the matrices aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices ๐ŸŒˆ

The default value for n is 30. The -fblas-matmul-limit option can be used to change this value ๐Ÿ’…

  • -frecursive โ€” ๐Ÿ” allows indirect recursion by forcing all local arrays to be allocated on the stack. You can't use this flag together with -fmax-stack-var-size= or -fno-automatic ๐Ÿšซ
  • -finit-local-zero, -finit-derived, -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan>, -finit-logical=<true|false>, -finit-character=n โ€” ๐Ÿซง this whole family handles initialization of local variables, so nothing starts out as random garbage.

-finit-local-zero tells the compiler to set local INTEGER, REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER variables to a string of null bytes. If you want finer-grained control, there are the -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real and imaginary parts of local COMPLEX variables), -finit-logical=<true|false>, and -finit-character=n options. Here n is an ASCII character value for the character one ๐ŸŽ€

With -finit-derived, components of derived type variables get initialized according to these flags. Components whose type isn't covered by an explicit -finit-* flag get treated as described above with -finit-local-zero โœจ

These options do not initialize:

  • objects with the POINTER attribute
  • allocatable arrays
  • variables that appear in an EQUIVALENCE statement

(These limitations may be removed in future releases ๐Ÿคž)

Note that -finit-real=nan initializes REAL and COMPLEX variables with a quiet NaN. For a signalling NaN, use -finit-real=snan. Heads up though: compile-time optimizations may convert those into a quiet NaN, and trapping needs to be enabled (e.g. via -ffpe-trap) ๐Ÿ”ฅ

The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. That value is then assigned to the integer variables in the Fortran code, which might wrap around if the value is too large for the kind ๐Ÿ˜ญ

Finally, enabling any of the -finit-* options will silence the warnings that -Wuninitialized would have emitted for the affected local variables ๐Ÿคซ

  • -falign-commons โ€” ๐Ÿงฑ by default, gfortran enforces proper alignment of all variables in a COMMON block by padding them as needed. On some platforms this is mandatory, and on others it boosts performance. If a COMMON block isn't declared with consistent data types everywhere, that padding can cause trouble, and -fno-align-commons can be used to disable the automatic alignment. Use the same form of this option for all files that share a COMMON block ๐Ÿซถ To avoid potential alignment issues in COMMON blocks, it's recommended to order objects from largest to smallest ๐Ÿ“
  • -fno-protect-parens: okay so by default the compiler respects your parentheses at every optimization level, so it never re-associates anything ๐Ÿ’… Add -fno-protect-parens and it's allowed to reorder REAL and COMPLEX expressions for faster code โœจ Heads up, bestie: that re-association also needs -fno-signed-zeros and -fno-trapping-math in effect ๐Ÿ™ˆ Parens protection is on by default, unless you pass -Ofast ๐Ÿ”ฅ
  • -frealloc-lhs: an allocatable left-hand side of an intrinsic assignment gets (re)allocated automatically if it's unallocated or has a different shape ๐Ÿฆ‹ It's on by default except when -std=f95 is given. See also -Wrealloc-lhs ๐Ÿ’œ
  • -faggressive-function-elimination: functions with identical argument lists get eliminated within statements, even if they aren't marked PURE ๐Ÿงš So something like this only makes a single call to f:
a = f(b,c) + f(b,c)

This only works if -ffrontend-optimize is in effect ๐Ÿซถ

  • -ffrontend-optimize: this one does front-end optimization by messing around with parts of the Fortran parse tree ๐ŸŒธ It's enabled by default by any -O option except -O0 and -Og. The optimizations it turns on include:
    • inlining calls to MATMUL,
    • getting rid of identical function calls within expressions,
    • removing unnecessary calls to TRIM in comparisons and assignments,
    • replacing TRIM(a) with a(1:LEN_TRIM(a)), and
    • short-circuiting logical operators (.AND. and .OR.).

If you want it gone, use -fno-frontend-optimize ๐Ÿ™…

  • -ffrontend-loop-interchange: the front end tries to swap loops whenever it's worth it ๐ŸŒˆ It's enabled by default by any -O option. Right now it only affects FORALL and DO CONCURRENT statements with several forall triplets ๐Ÿ“

โœจ ENVIRONMENT โœจ

gfortran doesn't read any environment variables of its own to control how it runs ๐Ÿ’œ It only uses the ones that already affect gcc.

๐Ÿ› BUGS ๐Ÿ›

Want to report a bug? Check out <file:///usr/share/doc/gcc-11/README.Bugs> for instructions ๐Ÿซถ

โœจ SEE ALSO โœจ

gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1) and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb ๐Ÿ“š

โœจ AUTHOR โœจ

For the contributors to GCC and GNU Fortran, check the Info entry for gfortran ๐Ÿง‘โ€๐Ÿ’ป

Copyright (c) 2004-2021 Free Software Foundation, Inc.

You're allowed to copy, distribute and/or modify this document under the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation ๐Ÿ“œ The Invariant Sections are "Funding Free Software", the Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). A copy of the license is in the gfdl(7) man page.

(a) The FSF's Front-Cover Text is: "A GNU Manual"

(b) The FSF's Back-Cover Text is: "You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development."


That's the whole page, bestie! ๐ŸŽ€ This version came from the gcc-11 build, last updated 2024-07-19, so you're fully caught up now ๐Ÿ’–๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from