GFORTRAN(1)

πŸ“¦
version 13.5.0+git10516 Β· 2 versions
, in opensuse-leap 16.0

🌈 gfortran(1) β€” GNU Fortran compiler 🌈

okay so bestie, this is the gfortran(1) page from the GNU manual β€” the GNU Fortran compiler. We’re gonna get you comfy with it, no cap.

πŸŽ€ NAME πŸŽ€

gfortran β€” 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 listed here; see below for the remainder.

πŸ¦‹ DESCRIPTION πŸ¦‹

gfortran is the GNU Fortran compiler, and it supports every option that gcc supports. This page only documents the options that are specifically GNU Fortran. πŸ’…

Every GCC option and every GNU Fortran option is accepted by both gfortran and gcc β€” and by any other driver built at the same time, like g++ β€” because adding GNU Fortran to the GCC distribution makes all the relevant drivers accept GNU Fortran options. ✨

Sometimes options have positive and negative forms; the negative form of -ffoo would be -fno-foo. This manual documents only one of those two forms, whichever one is not the default. 🫢

πŸ’… OPTIONS πŸ’…

Here’s the tea: this is a summary of all the options specific to GNU Fortran, grouped by type. The explanations are in the following sections. πŸ“š

πŸ“ 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
  • -static-libquadmath

⭐ 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 πŸ› οΈ

These are the knobs that decide which flavor of Fortran the compiler will accept, bestie:

  • -ffree-form β€” tells the compiler the source file uses free form layout, the layout that showed up in Fortran 90. ✨
  • -ffixed-form β€” tells the compiler the source file uses fixed form layout, the old-school layout traditionally used in older Fortran programs.

If you don’t specify either one, the source form is determined by the file extension. Cute, right? πŸŽ€

  • -fall-intrinsics β€” makes all intrinsic procedures get accepted, including the GNU-specific extensions. This can be useful with -std= when you wanna force standard-compliance but still get access to the full range of intrinsics available with gfortran. As a consequence, -Wintrinsics-std will be ignored, and no user-defined procedure with the same name as any intrinsic will be called except when it is explicitly declared EXTERNAL. πŸ‘‘
  • -fallow-argument-mismatch β€” some code contains calls to external procedures with mismatches between the calls and the procedure definition, or with mismatches between different calls. That code is non-conforming and will usually get flagged with an error. This option degrades the error to a warning, and that warning can only be disabled by disabling all warnings via -w. Only a single occurrence per argument is flagged by this warning. -fallow-argument-mismatch is implied by -std=legacy. 😭
🚨 Using this option is strongly discouraged. It is possible to provide standard-conforming code that allows different types of arguments by using an explicit interface and TYPE(*).
  • -fallow-invalid-boz β€” a BOZ literal constant can occur in a limited number of contexts in standard conforming Fortran. This option degrades an error condition to a warning, and allows a BOZ literal constant to appear where the Fortran standard would otherwise prohibit its use.
  • -fd-lines-as-code β€” enables special treatment for lines beginning with d or D in fixed form sources; those lines are treated as if the first column contained a blank.
  • -fd-lines-as-comments β€” enables special treatment for lines beginning with d or D in fixed form sources; those lines are treated as comment lines.
  • -fdec β€” DEC compatibility mode. Enables extensions and other features that mimic the default behavior of older compilers (such as DEC). These features are non-standard and should be avoided at all costs. For details on GNU Fortran’s implementation of these extensions, see the full documentation. πŸ’€

Other flags enabled by this switch 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 β€” enables the use of character literals in assignments and DATA statements for non-character variables.
  • -fdec-structure β€” enables DEC STRUCTURE and RECORD as well as UNION, MAP, and dot (.) as a member separator (in addition to %). This is provided for compatibility only; Fortran 90 derived types should be used instead where possible.
  • -fdec-intrinsic-ints β€” enables 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 such as COTAN and degree-valued trigonometric functions (e.g. TAND, ATAND, etc...) for compatibility with older code.
  • -fdec-static β€” enables DEC-style STATIC and AUTOMATIC attributes to explicitly specify the storage of variables and other objects.
  • -fdec-include β€” enables parsing of INCLUDE as a statement in addition to parsing it as an INCLUDE line. When parsed as an INCLUDE statement, INCLUDE does not have to be on a single line and can use line continuations.
  • -fdec-format-defaults β€” enables format specifiers F, G and I to be used without width specifiers; default widths will be 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 is unclear which rules to apply to implicit typing as different vendors implement different rules. Using $ in IMPLICIT statements is also rejected.
  • -fbackslash β€” changes the interpretation of backslashes in string literals from a single backslash character to "C-style" escape characters. The following combinations are expanded "\a", "\b", "\f", "\n", "\r", "\t", "\v", "\\", and "\0" to the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. Additionally, "\x"nn, "\u"nnnn and "\U"nnnnnnnn (where each n is a hexadecimal digit) are translated into the Unicode characters corresponding to the specified code points. All other combinations of a character preceded by \ are unexpanded. 🌈
  • -fmodule-private β€” sets the default accessibility of module entities to PRIVATE. Use-associated entities will not be accessible unless they are explicitly declared as PUBLIC.
  • -ffixed-line-length-n β€” sets the column after which characters are ignored in typical fixed-form lines in the source file, and, unless -fno-pad-source, 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 that the entire line is meaningful and that continued character constants never have implicit spaces appended to them 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 have spaces assumed (as if padded to that length) after the ends of short fixed-form lines. This is not done either if -ffixed-line-length-0, -ffixed-line-length-none or if -fno-pad-source option is used. With any of those options, continued character constants never have implicit spaces appended to them to fill out the line. 🫢
  • -ffree-line-length-n β€” sets the column after which characters get ignored in typical free-form lines of your source file. Default is 132, bestie. And n can be none, which means the entire line is meaningful (no cap, go off). Also -ffree-line-length-0 means the exact same thing as -ffree-line-length-none. ✨
  • -fmax-identifier-length=n β€” caps how long an identifier is allowed to be. Typical values: 31 (Fortran 95) and 63 (Fortran 2003 and later). Name your variables responsibly πŸ’…
  • -fimplicit-none β€” says no implicit typing allowed, unless an explicit IMPLICIT statement overrides it. Literally the equivalent of adding implicit none to the start of every procedure. No sneaky surprise variables, periodt.
  • -fcray-pointer β€” enables the Cray pointer extension, which gives you C-like pointer functionality. Retro but iconic πŸŽ€
  • -fopenacc β€” enables the OpenACC extensions. This includes OpenACC !$acc directives in free form and c$acc, *$acc and !$acc directives in fixed form, !$ conditional compilation sentinels in free form and c$, *$ and !$ sentinels in fixed form, and when linking, it arranges for the OpenACC runtime library to be linked in. Full package, no cap.
  • -fopenmp β€” enables the OpenMP extensions. Same deal: OpenMP !$omp directives in free form and c$omp, *$omp and !$omp directives in fixed form, !$ conditional compilation sentinels in free form and c$, *$ and !$ sentinels in fixed form, and when linking it arranges for the OpenMP runtime library to be linked in. Heads up: -fopenmp implies -frecursive. 🫢
  • -fno-range-check β€” disables range checking on results of simplification of constant expressions during compilation. Like, GNU Fortran will normally throw an error at compile time when simplifying a = 1. / 0. With this option, no error β€” and a gets assigned the value +Infinity. If an expression evaluates to a value outside the relevant range of [-HUGE():HUGE()], the expression gets replaced by -Inf or +Inf as appropriate. Same energy with DATA i/Z'FFFFFFFF'/ β€” that'll result in an integer overflow on most systems, but with -fno-range-check the value will "wrap around" and i will be initialized to -1 instead. Unhinged behaviour, honestly πŸ’€
  • -fdefault-integer-8 β€” sets the default integer and logical types to an 8 byte wide type. This option also affects the kind of integer constants like 42. Unlike -finteger-4-integer-8, it does not promote variables with explicit kind declaration. Know the difference, iykyk.
  • -fdefault-real-8 β€” sets the default real type to an 8 byte wide type. Also affects the kind of non-double real constants like 1.0. This option 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, DOUBLE PRECISION and double real constants are not promoted. And 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 an 10 byte wide type. Also affects the kind of non-double real constants like 1.0, and 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, 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 an 16 byte wide type. Same trio of behaviours: affects the kind of non-double real constants like 1.0, promotes the default width of DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes if possible, and skips that promotion if -fdefault-double-8 is given along with fdefault-real-16. Unlike -freal-4-real-16, fdefault-real-16 does not promote variables with explicit kind declarations. Big numbers, big energy ✨
  • -fdefault-double-8 β€” sets the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type. Does nothing if this is already the default (respect πŸ™Œ). This option prevents -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 an INTEGER(KIND=8) entities. If KIND=8 is unavailable, then an error will be issued. ⚠️ Use this one with care β€” 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. Inspection of the intermediate representation of the translated Fortran code, produced by -fdump-tree-original, is suggested. So do the vibe check before you commit, fr fr.
  • -freal-4-real-8, -freal-4-real-10, -freal-4-real-16, -freal-8-real-4, -freal-8-real-10, -freal-8-real-16 β€” promote all REAL(KIND=M) entities to REAL(KIND=N) entities. If REAL(KIND=N) is unavailable, then an error will be issued. The -freal-4- flags also affect the default real kind and the -freal-8- flags also the double-precision real kind. All other real-kind types are unaffected by this option. The promotion is also applied to real literal constants of default and double-precision kind and 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, and I/O and calls to intrinsic procedures when passing a value to the kind= dummy argument. Inspection of the intermediate representation of the translated Fortran code, produced by -fdump-fortran-original or -fdump-tree-original, is suggested. Same warning as before β€” this is main character energy but handle with care, bestie πŸ’…

  • -std=std β€” specifies the standard to which the program is expected to conform, and std may be one of f95, f2003, f2008, f2018, gnu, or legacy. The default value for std is gnu, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran, although warnings will be given for obsolete extensions not recommended for use in new code. The legacy value is equivalent but without the warnings for obsolete extensions, and may be useful for old non-standard programs (respect for the elders 🫑). The f95, f2003, f2008, and f2018 values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are 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 is only present for backwards compatibility with earlier gfortran versions and should not be used any more. Let it go, girl πŸ’€
  • -ftest-forall-temp β€” enhances test coverage by forcing most forall assignments to use temporary. Niche, but she's doing her job πŸŽ€

✨ Enable and customize preprocessing ✨

Okay so β€” many Fortran compilers, GNU Fortran included, let you pass the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) so you can do conditional compilation. In the case of GNU Fortran, this is the GNU C Preprocessor in traditional mode. Very vintage of her.

On systems with case-preserving file names, the preprocessor is automatically invoked if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. To manually invoke the preprocessor on any file, use -cpp; to disable preprocessing on files where the preprocessor is run automatically, use -nocpp. Easy πŸ’–

If a preprocessed file includes another file with the Fortran INCLUDE statement, the included file is not preprocessed. To preprocess included files, use the equivalent preprocessor statement #include. Important distinction, don't get caught out πŸ™ˆ

If GNU Fortran invokes the preprocessor, __GFORTRAN__ is defined. The macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ can be used to determine the version of the compiler. See Top,,Overview,cpp,The C Preprocessor for details.

GNU Fortran supports a number of INTEGER and REAL kind types in additional to the kind types required by the Fortran standard. The availability of any given kind type is architecture dependent (so like, check your build, ngl). The following pre-defined preprocessor macros can be used to conditionally include code for these additional kind types: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__. Slay, conditional compilation 🌈

While CPP is the de-facto standard for preprocessing Fortran code, Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional Compilation, which is not widely used and not directly supported by the GNU Fortran compiler. You can use the program coco to preprocess such files (http://www.daniellnagle.com/coco.html). Off the beaten path, but she exists πŸ¦‹

The following options control preprocessing of Fortran code:

  • -cpp, -nocpp β€” enable preprocessing. The preprocessor is automatically invoked if the file extension is .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03 or .F08. Use this option to manually enable preprocessing of any kind of Fortran file.

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

The preprocessor is run in traditional mode. Any restrictions of the file-format, especially the limits on line length, apply for preprocessed output as well, so it might be advisable to use the -ffree-line-length-none or -ffixed-line-length-none options. Learn from my mistakes bestie 😭
  • -dM β€” instead of the normal output, generate a list of #define directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is 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. Chef's kiss, go peek at your own compiler's secrets πŸ‘‘

  • -dD β€” bestie this one is almost -dM except in two whole ways: 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. Two-for-one deal πŸ’…
  • -dN β€” like -dD, but it only emits the macro names, not their expansions. Names only, no lore πŸ™ˆ
  • -dU β€” like dD except only macros that are expanded, or whose definedness is tested in preprocessor directives, get 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. It's giving "I'll tell you when it actually matters" energy ✨
  • -dI β€” outputs #include directives in addition to the result of preprocessing. Showing you the receipts of where everything came from 🧾
  • -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 is on, 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 that with the negated form -fno-working-directory. Heads up though: if the -P flag is present on the command line, this option has no effect, because no #line directives are emitted whatsoever. lowkey tragic 😭
  • -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; peep --sysroot and -isysroot. Queue's full, get in the back 🫢
  • -imultilib dir β€” use dir as a subdirectory of the directory containing target-specific C++ headers.
  • -iprefix prefix β€” specifies prefix as the prefix for subsequent -iwithprefix options. If the prefix represents a directory, bestie you should include the final /. Don't forget it, I'm begging πŸŽ€
  • -isysroot dir β€” this option is like the --sysroot option, but applies only to header files. See the --sysroot option for more info.
  • -iquote dir β€” searches dir only for header files requested with #include "file"; they are not searched for #include <file>, before all directories specified by -I and before the standard system directories. If dir begins with =, then the = gets replaced by the sysroot prefix; see --sysroot and -isysroot. Exclusive club, quote-includes only πŸ’…
  • -isystem dir β€” searches dir for header files, after all directories specified by -I but before the standard system directories. It marks it as a system directory, so it gets the same special treatment as is applied to the standard system directories. If dir begins with =, then the = gets replaced by the sysroot prefix; see --sysroot and -isysroot. VIP section but make it system ✨
  • -nostdinc β€” do not search the standard system directories for header files. Only the directories you've specified with -I options (and the directory of the current file, if appropriate) are searched. You're on your own, babe 🫑
  • -undef β€” do not predefine any system-specific or GCC-specific macros. The standard predefined macros stay defined though, no cap.
  • -Apredicate=answer β€” make an assertion with the predicate predicate and answer answer. This form is preferred to the older form -A predicate(answer), which is still supported, because it doesn't use shell special characters. Glow-up form, honestly πŸ‘‘
  • -A-predicate=answer β€” cancel an assertion with the predicate predicate and answer answer. Never mind, ignore that πŸ’€
  • -C β€” do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which get deleted along with the directive.

You should be prepared for side effects when using -C; it causes the preprocessor to treat comments as tokens in their own right. For example, comments appearing at the start of what would be a directive line have the effect of turning 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 β€” do not discard comments, including during macro expansion. This is like -C, except that comments contained within macros are also passed through to the output file where the macro is expanded.

In addition to the side-effects of the -C option, the -CC option causes all C++-style comments inside a macro to be converted to C-style comments. This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line. The -CC option 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 β€” predefine name as a macro, with definition 1. Simple. Iconic. Understood 🌸
  • -Dname=definition β€” the contents of definition are tokenized and processed as if they appeared during translation phase three in a #define directive. In particular, the definition will be truncated by embedded newline characters. Yeah, it just stops. Rude but true βœ‚οΈ

If you're invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.

If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful 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 are given on the command line. And listen β€” all -imacros file and -include file options are processed after all -D and -U options. Order matters, bestie 🫢

  • -H β€” print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the #include stack it is. It's giving nesting doll energy πŸͺ†
  • -P β€” inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers. Protect the confused little programs 😭
  • -Uname β€” cancel any previous definition of name, either built in or provided with a -D option. Undefined, unbothered, unbothered-and-undefined πŸ’…

πŸ’– Options to request or suppress errors and warnings πŸ’–

Okay so real talk β€” errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler will keep processing the program in an attempt to report further errors to aid in debugging, but it will not produce any compiled output. Nothing. Nada. 😭

Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there is likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. Just a little girl, be careful πŸŽ€

You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default. iykyk ✨

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

  • -fmax-errors=n β€” limits the maximum number of error messages to n, at which point GNU Fortran bails out rather than attempting to continue processing the source code. If n is 0, there is no limit on the number of error messages produced. Zero equals infinite, make it make sense πŸ˜…
  • -fsyntax-only β€” check the code for syntax errors, but do not actually compile it. This will generate module files for each module present in the code, but no other output file. Vibes check only, no commitment πŸ¦‹
  • -Wpedantic, -pedantic β€” issue warnings for uses of extensions to Fortran. -pedantic also applies to C-language constructs where they occur in GNU Fortran source files, such as use of \e in a character constant within a directive like #include.

Valid Fortran programs should compile properly with or without this option. However, without this option, certain GNU extensions and traditional Fortran features are supported as well. With this option, many of them are rejected. Slay, but strict πŸ’…

Some users try to use -pedantic to check programs for conformance. They soon find that it does not do quite what they want---it finds some nonstandard practices, but not all. However, improvements to GNU Fortran in this area are welcome. (fr fr, submit a patch bestie πŸ™)

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

  • -pedantic-errors β€” like -pedantic, except that errors are produced rather than warnings. Same energy, way more dramatic πŸ”₯
  • -Wall β€” enables commonly used warning options pertaining to usage that 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. It's the starter pack of warnings, lowkey essential πŸ‘‘
  • -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)

Same variable, two jobs, no consent. Not the vibe 🚩

  • -Wampersand β€” warns about 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 initiated the continuation. So it just... guesses. Generously 🫢
  • -Warray-temporaries β€” warns about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries. Not just snitching β€” actually helpful πŸ’œ
  • -Wc-binding-type β€” warns you when a variable might not be C interoperable 🫢 like, specifically when it's declared with an intrinsic type using default kind instead of a kind parameter from the ISO_C_Binding module that's actually defined for C interop. This one is implied by -Wall.
  • -Wcharacter-truncation β€” yells at you when a character assignment is gonna truncate the string you're assigning. bestie the string is getting chopped, pay attention 😭
  • -Wline-truncation β€” warns when a source code line is gonna be truncated. Implied by -Wall. And heads up: for free-form source code the default is -Werror=line-truncation, so those truncations get reported as an error πŸ’€
  • -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. Note: this one does not imply -Wconversion.
  • -Wextra β€” turns on some warning options for usages of language features that might be problematic. Right now that includes -Wcompare-reals, -Wunused-parameter and -Wdo-subscript.
  • -Wfrontend-loop-interchange β€” warns when -ffrontend-loop-interchange is used to do loop interchanges.
  • -Wimplicit-interface β€” warns if a procedure is called without an explicit interface. Careful though: 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. Example: 3/5 evaluates to 0. yeah. iconic integer math behavior ✨
  • -Wintrinsics-std β€” warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (with -std) and treats it as an EXTERNAL procedure because of that. You can use -fall-intrinsics to never trigger this behavior and always link to the intrinsic regardless of the selected standard.
  • -Wno-overwrite-recursive β€” don't warn when -fno-automatic is used with -frecursive. Recursion will be broken if the relevant local variables don't have the AUTOMATIC attribute explicitly declared. You can use this option to suppress the warning when you know recursion isn't broken. Useful for build environments that use -Werror.
  • -Wreal-q-constant β€” produces a warning if a real-literal-constant contains a q exponent-letter.
  • -Wsurprising β€” produces a warning when "suspicious" code constructs are encountered. Technically legal, but like... they usually mean a mistake happened πŸ‘€

This currently produces a warning under the following circumstances:

  • 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 is 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 enabled, this is an error.
  • A CHARACTER variable is declared with negative length.
  • With -fopenmp, for fixed-form source code, when an omx vendor-extension sentinel is encountered. (The equivalent ompx, used in free-form source code, is diagnosed by default.)
  • -Wtabs β€” so by default tabs are accepted as whitespace, but tabs are not members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported. -Wtabs makes a warning get issued if a tab is encountered. Note that -Wtabs is active for -pedantic, -std=f95, -std=f2003, -std=f2008, -std=f2018 and -Wall.
  • -Wundefined-do-loop β€” warns if a DO loop with step either 1 or -1 yields an underflow or an overflow during iteration of an induction variable of the loop. Implied by -Wall.
  • -Wunderflow β€” produces a warning when numerical constant expressions are encountered that yield an UNDERFLOW during compilation. Enabled by default ⭐
  • -Wintrinsic-shadow β€” warns if a user-defined procedure or module procedure has the same name as an intrinsic. In that case, an explicit interface or EXTERNAL or INTRINSIC declaration might be needed so calls later resolve to the intrinsic/procedure you actually wanted. Implied by -Wall.
  • -Wuse-without-only β€” warns if a USE statement has no ONLY qualifier and thus implicitly imports all public entities of the used module. main character module energy, importing everything smh πŸ’…
  • -Wunused-dummy-argument β€” warns about unused dummy arguments. Implied by -Wall.
  • -Wunused-parameter β€” okay this one is a plot twist: contrary to gcc's meaning of -Wunused-parameter, gfortran's implementation does not warn about unused dummy arguments (that's -Wunused-dummy-argument), it warns about unused PARAMETER values. -Wunused-parameter is implied by -Wextra if -Wunused or -Wall is also used.
  • -Walign-commons β€” by default gfortran warns about any occasion of variables being padded for proper alignment inside a COMMON block. You can turn that warning off 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 reduce performance. If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g. (:,:,:)) for the variable on the left-hand side to prevent the reallocation check. Note that in some cases the warning is shown even if the compiler will optimize reallocation checks away β€” for instance, when the right-hand side contains the same variable multiplied by a scalar. See also -frealloc-lhs.
  • -Wrealloc-lhs-all β€” warns when the compiler inserts code for allocation or reallocation of an allocatable variable; this includes scalars and derived types.
  • -Wcompare-reals β€” warns when comparing real or complex types for equality or inequality. Implied by -Wextra. (floating point equality my beloved disaster 🌸)
  • -Wtarget-lifetime β€” warns if the pointer in a pointer assignment might be longer than its target. Implied by -Wall.
  • -Wzerotrip β€” warns if a DO loop is known to execute zero times at compile time. 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 is actually executed, in cases like
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. no mercy, no warnings, only consequences πŸ”₯
Some of these have no effect when compiling programs written in Fortran.

πŸ› Options for debugging your program or GNU Fortran πŸ›

GNU Fortran has various special options that are used for debugging either your program or the GNU Fortran compiler itself. iykyk πŸ’œ

  • -fdump-fortran-original β€” outputs the internal parse tree after translating the source program into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added πŸ™ˆ
  • -fdump-fortran-optimized β€” outputs the parse tree after front-end optimization. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added.
  • -fdump-parse-tree β€” outputs the internal parse tree after translating the source program into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added. This option is deprecated; use -fdump-fortran-original instead.
  • -fdebug-aux-vars β€” renames internal variables created by the gfortran front end and makes them accessible to a debugger. The name of the internal variables then starts with upper-case letters followed by an underscore. This option is useful for debugging the compiler's code generation together with -fdump-tree-original and enabling debugging of 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 generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added.
  • *-ffpe-trap=list* β€” specify a list of floating point exception traps to enable. On most systems, if a floating point exception occurs and the trap for that exception is enabled, a SIGFPE signal will be sent and the program being aborted, producing a core file useful for debugging. list is a (possibly empty) comma-separated list of the following 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), and denormal (operation performed on a denormal value). The first five exceptions correspond to the five IEEE 754 exceptions, whereas the last one (denormal) is not part of the IEEE 754 standard but is available on some common architectures such as x86. πŸ’€ trap card activated

The first three exceptions (invalid, zero, and overflow) are usually giving serious error, okay? Like, unless your program literally has a whole plan for dealing with them, turning traps on for those three is lowkey the move β€” bestie, just do it.

If you pass the option more than once on the command line, the lists get joined together: "ffpe-trap="list1 "ffpe-trap="list2 is the same thing as "ffpe-trap="list1,list2. Stack 'em, they merge. ✨

Heads up: once an exception is enabled, it cannot be disabled β€” there's no negative form. Not me finding out the hard way 😭. Also "ffpe-trap=inexact" is probably uninteresting in practice because like, so many floating point ops lose precision from rounding, it's basically everyone's everyday vibe.

By default, no exception traps are enabled. Zero. None. Chill.

  • -ffpe-summary=list β€” tells the compiler which floating-point exceptions should have their flag status printed to ERROR_UNIT when you invoke STOP and ERROR STOP. The list can be none, all, or a comma-separated list of these exceptions: invalid, zero, overflow, underflow, inexact and denormal. (Peep -ffpe-trap above for what each exception actually means πŸ’….) If you use this option more than once on the command line, only the last one counts β€” no merging here, unlike its sister option. By default, a summary for all exceptions but inexact is shown.
  • -fno-backtrace β€” so when a serious runtime error hits, or a deadly signal gets emitted (segmentation fault, illegal instruction, bus error, floating-point exception, and all the other POSIX signals that have the action core), the Fortran runtime library tries to output a backtrace of the error. This option disables that backtrace generation. Important caveat though: this option only has influence for compilation of the Fortran main program. Main character only, bestie πŸ‘‘.

These options control how GNU Fortran searches for files specified by the INCLUDE directive, and where it goes looking for previously compiled modules. It also affects the search paths that cpp uses when it preprocesses Fortran source. Search party energy πŸ”.

  • -Idir β€” these affect how the INCLUDE directive is interpreted (and also the #include directive of the cpp preprocessor, iykyk). Also note the general behavior of -I and INCLUDE is pretty much the same as -I with #include in the cpp preprocessor, as far as looking for header.gcc files and other such things go. This path is also used to search for .mod files when previously compiled modules are needed by a USE statement. One flag, so many jobs πŸ’….
  • -Jdir β€” specifies where to put .mod files for compiled modules. It also gets added to the list of directories searched by a USE statement. The default is the current directory. πŸŽ€
  • -fintrinsic-modules-path dir β€” specifies the location of pre-compiled intrinsic modules, in case they're not chilling in the default location the compiler expects.

πŸ’– Influencing the linking step πŸ’–

These options come into play when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're meaningless β€” literally no thoughts, head empty πŸ™ˆ.

  • -static-libgfortran β€” on systems that provide libgfortran as both a shared and a static library, this forces the use of the static version. If no shared version of libgfortran was built when the compiler was configured, this option has no effect. Cute but useless, love that for it.
  • -static-libquadmath β€” same deal, but for libquadmath: on systems that provide it as a shared and a static library, this forces the use of the static version. And again, if no shared version of libquadmath was built when the compiler was configured, this option has no effect.
⚠️ Okay so, important licensing tea: the libquadmath runtime library is licensed under the GNU Lesser General Public License (LGPL), and linking it statically introduces requirements when redistributing the resulting binaries. Not me ignoring the LGPL 😭 β€” read it before you ship.

πŸ¦‹ Influencing runtime behavior πŸ¦‹

These options affect the runtime behavior of programs compiled with GNU Fortran. Runtime era ✨.

  • -fconvert=conversion β€” specify the representation of data for unformatted files. Valid values for conversion on most systems 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

On POWER systems which support -mabi=ieeelongdouble, there are additional options, which can be combined with others with commas. Those are:

  • -fconvert=r16_ieee β€” Use IEEE 128-bit format for REAL(KIND=16).
  • -fconvert=r16_ibm β€” Use IBM long double format for REAL(KIND=16).

This option only has an effect when used in the main program. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable override the default specified by -fconvert. So like, they win, periodt.

  • -frecord-marker=length β€” specify the length of record markers for unformatted files. Valid values for length are 4 and 8. Default is 4. Bestie, this is different from previous versions of gfortran, which specified a default record marker length of 8 on most systems. So if you wanna read or write files compatible with earlier versions of gfortran, use -frecord-marker=8. Time-travel flag πŸ•°οΈ.
  • -fmax-subrecord-length=length β€” specify the maximum length for a subrecord. The maximum permitted value for length is 2147483639, which is also the default. Only really useful for use by the gfortran testsuite β€” respectfully, this one's not for you, it's for the test girlies πŸ’€.
  • -fsign-zero β€” when enabled, floating point numbers of value zero with the sign bit set are written as negative number in formatted output, and treated as negative in the SIGN intrinsic. The -fno-sign-zero form does not print the negative sign of zero values (or values rounded to zero for I/O) and regards 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. Very "how do we all agree to behave" of them.

Most of them have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed β€” the one which is not the default. You can figure out the other form by either removing no- or adding it. Math queen behaviour 🧚.

  • -fno-automatic β€” treat each program unit (except those marked as RECURSIVE) as if the SAVE statement were specified for every local variable and array referenced in it. Does not affect common blocks. (Some Fortran compilers provide this option under the name -static or -save.) The default, which is -fautomatic, uses the stack for local variables smaller than the value given by -fmax-stack-var-size. Use the option -frecursive to use no static memory. Local variables or arrays having an explicit SAVE attribute are silently ignored unless the -pedantic option is added πŸ™ˆ.
  • -ff2c β€” generate code designed to be compatible with code generated by g77 and f2c. The calling conventions used by g77 (originally implemented in f2c) require functions that return type default REAL to actually return the C type double, and functions that return type COMPLEX to return the values via an extra argument in the calling sequence that points to where to store the return value. Under the default GNU calling conventions, such functions simply return their results as they would in GNU C β€” default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. Additionally, this option implies the -fsecond-underscore option, unless -fno-second-underscore is explicitly requested. This does not affect the generation of code that interfaces with the libgfortran library.
⚠️ Caution: it is not a good idea to mix Fortran code compiled with -ff2c with code compiled with the default -fno-f2c calling conventions, because calling COMPLEX or default REAL functions between program parts which were compiled with different calling conventions will break at execution time. Like, break break. 😭
⚠️ Caution: this will break code which passes intrinsic functions of type default REAL or COMPLEX as actual arguments, as the library implementations use the -fno-f2c calling conventions. Fr fr, it's giving incompatibility.
  • -fno-underscoring β€” do not transform names of entities specified in the Fortran source file by appending underscores to them. With -funderscoring in effect, GNU Fortran appends one underscore to external names β€” this is done to ensure compatibility with code produced by many UNIX Fortran compilers.
⚠️ Caution: the default behavior of GNU Fortran is incompatible with f2c and g77, so please use the -ff2c option if you want object files compiled with GNU Fortran to be compatible with object code created with these tools.

Use of -fno-underscoring is not recommended unless you're out here experimenting with issues such as integration of GNU Fortran into existing system environments (vis-Γ -vis existing libraries, tools, and so on). Bestie, this is lab-experiment territory πŸ§ͺ.

For example, with -funderscoring, and assuming that j() and max_count() are external functions while my_var and lvar are local variables, a statement like

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

is implemented as something akin to:

        i = j_() + max_count_(&my_var, &lvar);

With -fno-underscoring, the same statement is implemented as:

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

Use of -fno-underscoring allows direct specification of user-defined names while debugging and when interfacing GNU Fortran code with other languages. Slay 🫢.

Note that just because the names match does not mean the interface implemented by GNU Fortran for an external name matches the interface implemented by some other language for that same name. That is, getting code produced by GNU Fortran to link to code produced by some other compiler using this or any other method can be only a small part of the overall solution β€” getting the code generated by both compilers to agree on issues other than naming can require significant effort, and, unlike naming disagreements, linkers normally cannot detect disagreements in these other areas. The linker is not a vibe-checker, sadly πŸ’€.

Also, note that with -fno-underscoring, the lack of appended underscores introduces the very real possibility that a user-defined external name will conflict with a name in a system library, which could make finding unresolved-reference bugs quite difficult in some cases β€” they might occur at program run time, and show up only as buggy behavior at run time. Truly the worst kind of surprise 😭.

…and so, in future versions of GNU Fortran the dream is to sort out the naming and linking situation so that debugging always uses the names exactly as they appear in your source β€” even if the linker is out here seeing mangled versions of them, which, to be clear, only happens to stop you accidentally linking procedures whose interfaces don't match. πŸ’…


  • -fsecond-underscore β€” bestie, by default GNU Fortran slaps one underscore onto external names. Use this option and it gets ✨fancy✨: two underscores for names that already contain underscores, and one underscore for external names that don't have any. It also appends two underscores to internal names that contain underscores, so they don't collide with external names. πŸŽ€

This option does nothing if -fno-underscoring is in effect. And it's implied by the -ff2c option.

Otherwise, with this option on, an external name like "MAX_COUNT" becomes a reference to the link-time external symbol "max_count__" instead of "max_count_". That's required for compatibility with g77 and f2c, and it's implied by using the -ff2c option. iykyk 🫢

  • -fcoarray=<keyword> β€” coarrays, but make it a keyword situation:
    • none β€” disable coarray support. Using coarray declarations and image-control statements will produce a compile-time error. (This is the default, btw.)
    • single β€” single-image mode, meaning num_images() is always one. Simple. Iconic. πŸ¦‹
    • lib β€” library-based coarray parallelization; you'll need to link a suitable GNU Fortran coarray library. πŸ”₯
  • -fcheck=<keyword> β€” turns on run-time checks! The argument has to be a comma-delimited list of these keywords, and if you prefix a check with no- it disables that check β€” but only if it got activated by a previous specification. Sneaky but valid. πŸ’…
    • all β€” enable all run-time tests of -fcheck.
    • array-temps β€” warns at run time when a temporary array had to be generated for passing an actual argument. That info is sometimes genuinely useful in optimization, so you can avoid such temporaries. ✨
Note: the warning is only printed once per location.
  • bits β€” run-time checks for invalid arguments to the bit manipulation intrinsics.
  • bounds β€” run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds, and ensures all string lengths are equal for character array constructors without an explicit typespec.

Some checks require that -fcheck=bounds is set for the compilation of the main program.

Note: in the future this may also include other forms of checking, e.g., checking substring references.
  • do β€” run-time checks for invalid modification of loop iteration variables. Do not touch, bestie. 😭
  • mem β€” run-time checks for memory allocation.
Note: this option does not affect explicit allocations using the "ALLOCATE" statement β€” those are always checked.
  • pointer β€” run-time checks for pointers and allocatables.
  • recursion β€” run-time checks for recursively called subroutines and functions that are not marked as recursive. See also -frecursive.
Note: this check does not work for OpenMP programs, and is disabled if used together with -frecursive and -fopenmp.

Example! Assuming you have a file foo.f90, the command

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

will compile the file with all checks enabled as specified above, except warnings for generated array temporaries. Slay. πŸ‘‘

  • -fbounds-check β€” deprecated alias for -fcheck=bounds. (Old news, but she's still here.)
  • -ftail-call-workaround, -ftail-call-workaround=n β€” okay so some C interfaces to Fortran codes violate the gfortran ABI by omitting the hidden character length arguments as described in (the reference is literally blank in this manpage, love that for us) β€” and that can lead to crashes because pushing arguments for tail calls can overflow the stack. πŸ’€

To work around this for existing binary packages, this option disables 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 the equivalent -ftail-call-workaround, it's disabled only in gfortran procedures with character arguments that call implicitly prototyped procedures.

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 be used to generate prototypes that conform to gfortran's ABI, for inclusion in the source code.

Support for this option will likely be withdrawn in a future release of gfortran.

The negative form, -fno-tail-call-workaround or the equivalent -ftail-call-workaround=0, can be used to disable this option.

Default is currently -ftail-call-workaround β€” this will change in future releases.

  • -fcheck-array-temporaries β€” deprecated alias for -fcheck=array-temps. Same vibe, older name. πŸŽ€
  • -fmax-array-constructor=n β€” use this to increase the upper limit permitted in array constructors. The code below literally requires this option to 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 largest array that gets put on the stack. If the size is exceeded, static memory is used instead (except in procedures marked as RECURSIVE). Use -frecursive to allow for recursive procedures that don't have a RECURSIVE attribute, or for parallel programs. Use -fno-automatic to never use the stack at all. 🌸

Right now this option 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 behavior.

The default value for n is 65536.

  • -fstack-arrays β€” adding this makes the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory. If your program uses very large local arrays, you might have to extend your runtime limits for stack memory 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 as possible. Heads up: code compiled with this option is likely to be incompatible with code compiled without it, and it may execute slower. Trade-offs, bestie. πŸ’…
  • -frepack-arrays β€” in some circumstances GNU Fortran may pass assumed shape array sections via a descriptor describing a noncontiguous area of memory. This option adds code to the function prologue that repacks the data into a contiguous block at runtime. 🧚

That should result in faster accesses to the array. However, it can introduce significant overhead to the function call, especially when the passed data is noncontiguous.

  • -fshort-enums β€” provided for interoperability with C code that was compiled with the -fshort-enums option. It makes GNU Fortran choose the smallest "INTEGER" kind that a given enumerator set will fit in, and gives all its enumerators that kind. πŸ“
  • -finline-arg-packing β€” so when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size (or as an argument to a procedure that doesn't have an explicit interface), the argument may have to be packed, meaning put into contiguous memory. An example is 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 gets performed by inline code. This allows for more optimization, at the cost of increasing code size. πŸ”₯

-finline-arg-packing is implied by any of the -O options, except when optimizing for size via -Os. If the code contains a very large number of arguments that have to be packed, code size and also compilation time may become excessive. If that's the case, it may be better to disable this option. Instances of packing can be found by using -Warray-temporaries.

  • -fexternal-blas β€” makes gfortran generate calls to BLAS functions for some matrix operations like "MATMUL" instead of using our own algorithms β€” but only if the size of the matrices involved is larger than a given limit (see -fblas-matmul-limit). This may be profitable if an optimized vendor BLAS library is available. The BLAS library will have to be specified at link time. πŸ‘‘
  • -fblas-matmul-limit=n β€” only significant when -fexternal-blas is in effect. Matrix multiplication of matrices with size larger than (or equal to) n will be performed by calls to BLAS functions, while the others get handled by gfortran internal algorithms. If the matrices involved are not square, the size comparison is performed using 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 may result in code size increase if the size of the matrix can't be determined at compile time, because code for both cases is generated. Setting "-finline-matmul-limit=0" disables inlining in all cases. Setting this option with a value of n will produce inline code for matrices with size up to n. If the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices. 🌈

The default value for n is 30. The "-fblas-matmul-limit" can be used to change this value.

  • -frecursive β€” lets indirect recursion actually happen by forcing every local array to live on the stack. 🫢 One little catch though: you can't use this together with -fmax-stack-var-size= or -fno-automatic. They do not coexist, periodt.
  • -finit-local-zero, -finit-derived, -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan>, -finit-logical=<true|false>, -finit-character=n β€” okay so the init squad πŸ’…. -finit-local-zero tells the compiler to initialize 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 control there's the whole glow-up lineup: -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (this one also initializes the real and imaginary parts of local COMPLEX variables, iconic), -finit-logical=<true|false>, and -finit-character=n (where n is an ASCII character value).

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. slay.

Bestie, 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 β€” so like, watch this space πŸ™ˆ.)

Ngl, note that the -finit-real=nan option initializes REAL and COMPLEX variables with a quiet NaN. For a signalling NaN use -finit-real=snan β€” but heads up, compile-time optimizations may convert them into quiet NaN and trapping needs to be enabled (e.g. via -ffpe-trap). So it's giving "works but read the fine print" 😭.

Also -finit-integer will parse the value into an integer of type INTEGER(kind=C_LONG) on the host. Said value is then assigned to the integer variables in the Fortran code, which might result in wraparound if the value is too large for the kind. Lowkey a vibe check on your number sizes πŸ’€.

Finally, note that enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables. So like, you traded warnings for initialization, fair trade fr fr.

  • -falign-commons β€” by default, gfortran enforces proper alignment of all variables in a COMMON block by padding them as needed. On certain platforms this is mandatory, on others it increases performance. But if a COMMON block isn't declared with consistent data types everywhere, this padding can cause trouble, and -fno-align-commons can be used to disable automatic alignment. ✨ Important: the same form of this option should be used for all files that share a COMMON block. And to avoid potential alignment issues in COMMON blocks, it's recommended to order objects from largest to smallest. Main character energy: biggest to smallest, always πŸ‘‘.
  • -fno-protect-parens β€” by default the parentheses in expressions are honored for all optimization levels such that the compiler doesn't do any re-association. Using -fno-protect-parens allows the compiler to reorder REAL and COMPLEX expressions to produce faster code. 🏎️ Note that for the re-association optimization -fno-signed-zeros and -fno-trapping-math need to be in effect. The parentheses protection is enabled by default, unless -Ofast is given.
  • -frealloc-lhs β€” an allocatable left-hand side of an intrinsic assignment is automatically (re)allocated if it's either unallocated or has a different shape. The option is enabled by default except when -std=f95 is given. See also -Wrealloc-lhs. She reallocates, she adapts, she thrives πŸ’–.
  • -faggressive-function-elimination β€” functions with identical argument lists are eliminated within statements, regardless of whether these functions are marked PURE or not. For example, in
          a = f(b,c) + f(b,c)

there will only be a single call to f. Only works if -ffrontend-optimize is in effect, so like, they're a package deal πŸŽ€.

  • -ffrontend-optimize β€” this option performs front-end optimization, based on manipulating parts the Fortran parse tree. Enabled by default by any -O option except -O0 and -Og. Optimizations enabled by this option include:
    • inlining calls to MATMUL,
    • elimination 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 of logical operators (.AND. and .OR.).

It can be deselected by specifying -fno-frontend-optimize. Byeee πŸ‘‹.

  • -ffrontend-loop-interchange β€” attempt to interchange loops in the Fortran front end where profitable. Enabled by default by any -O option. At the moment, this option only affects FORALL and DO CONCURRENT statements with several forall triplets. Loop swap slay πŸ”„.

🌸 ENVIRONMENT 🌸

The gfortran compiler currently does not make use of any environment variables to control its operation above and beyond those that affect the operation of gcc. That's it, that's the section 🫢.


πŸ’€ BUGS πŸ’€

For instructions on reporting bugs, see <https://bugs.opensuse.org/>. Go off, tell them everything πŸ”₯.


πŸ¦‹ 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. The whole friend group, honestly 🫢✨.


πŸŽ€ AUTHOR πŸŽ€

See the Info entry for gfortran for contributors to GCC and GNU Fortran. Respect the icons who built this πŸ’œ.


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

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being "Funding Free Software", the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included 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.

Okay that's the whole page bestie, we ate and left no crumbs πŸ’…βœ¨ This lil doc drop is from gcc-13, dated 2026-09-10 β€” the GFORTRAN(1) era, iconic as always πŸŒˆπŸ’–