GFORTRAN(1)

πŸ“¦
version 13.5.0 Β· 5 versions
, in ubuntu stonking

πŸ¦‹ gfortran β€” the GNU Fortran compiler πŸ¦‹

okay so bestie, welcome to the Fortran zone πŸ’– this page is a whole journey: every flag, every quirk, every "please don't do this" β€” and we are reading all of it together, no skimming, no skipping, periodt.


πŸ’– NAME πŸ’–

gfortran β€” GNU Fortran compiler. short, sweet, iconic, that's her.

πŸŽ€ SYNOPSIS πŸŽ€

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

ngl only the most useful options are sitting up there looking cute β€” the rest are down below, so keep scrolling πŸ’…

πŸ’œ DESCRIPTION πŸ’œ

The gfortran command supports every single option that the gcc command supports. only the ones that are specific to GNU Fortran get written up here though, because the rest already have their own moment elsewhere.

Every GCC option and every GNU Fortran option is accepted by gfortran and by gcc β€” plus literally any other driver built at the same time, like g++ β€” because once GNU Fortran joins the GCC distribution, all the relevant drivers start accepting GNU Fortran options too. they share. we love that. 🫢

Sometimes options have a positive form and a negative form, and the negative form of -ffoo would be -fno-foo. this manual documents only one of those two forms: whichever one is not the default. so if you can't find the vibe you expected, that's why. iykyk.

✨ OPTIONS ✨

Here's the whole summary of every option specific to GNU Fortran, grouped by type. explanations are in the sections that follow this one. 🌈

πŸ“ 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 flags that decide exactly which flavour of Fortran the compiler is willing to vibe with:

  • -ffree-form, -ffixed-form β€” pick the layout your source file is using. free form is the Fortran 90 girlie; fixed form is what all the old-school Fortran programs were raised on. if you don't say either one, the source form gets figured out from the file extension. ✨
  • -fall-intrinsics β€” this one makes all intrinsic procedures get accepted, GNU-specific extensions included πŸ‘‘. super handy when you're using -std= to force standard-compliance but still want the full range of intrinsics gfortran has to offer. the catch: -Wintrinsics-std gets ignored as a result, and no user-defined procedure sharing a name with an intrinsic will ever get 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 would normally get flagged with an error. this option downgrades the error to a warning, which you can only turn off by turning off all warnings via -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 is possible to write standard-conforming code that allows different types of arguments by using an explicit interface and TYPE(*). do that instead bestie 😭
  • -fallow-invalid-boz β€” a BOZ literal constant can only show up in a limited number of contexts in standard conforming Fortran. this option turns an error condition into a warning and lets a BOZ literal constant appear in places where the Fortran standard would otherwise forbid it. πŸ’€
  • -fd-lines-as-code, -fd-lines-as-comments β€” special treatment for lines starting with d or D in fixed form sources. if you pass -fd-lines-as-code, they're treated as if the first column contained a blank. if you pass -fd-lines-as-comments, they're treated as comment lines.
  • -fdec β€” DEC compatibility mode πŸ•°οΈ. turns on extensions and other features that mimic how older compilers (like DEC) behaved by default. these features are non-standard and should be avoided at all costs. for the details of how GNU Fortran implements these extensions, see the full documentation.

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

and if -fd-lines-as-code/-fd-lines-as-comments aren't set, then -fdec also sets -fd-lines-as-comments.

  • -fdec-char-conversions β€” enables character literals in assignments and DATA statements for non-character variables.
  • -fdec-structure β€” enables DEC STRUCTURE and RECORD, plus UNION, MAP, and the dot (.) as a member separator (on top of %). this is for compatibility only β€” where possible, use Fortran 90 derived types instead.
  • -fdec-intrinsic-ints β€” enables the B/I/J/K kind variants of the integer functions that already exist (like BIAND, IIAND, JIAND, etc...). for the complete list of intrinsics, see the full documentation.
  • -fdec-math β€” enables legacy math intrinsics like COTAN and the degree-valued trigonometric functions (like TAND, ATAND, etc...) for compatibility with older code.
  • -fdec-static β€” enables DEC-style STATIC and AUTOMATIC attributes, so you can explicitly state 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 live 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. literally nothing after the final comma.
  • -fdollar-ok β€” allows $ as a valid non-first character in a symbol name. symbols that start with $ get rejected, because it's unclear which rules should apply to implicit typing since different vendors implement different rules. using $ in IMPLICIT statements is rejected too.
  • -fbackslash β€” changes how backslashes in string literals are interpreted: instead of one plain backslash character, you get "C-style" escape characters πŸ’…. these combos expand: \a, \b, \f, \n, \r, \t, \v, \\, and \0 become the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. on top of that, \xnn, \unnnn and \Unnnnnnnn (where each n is a hexadecimal digit) get translated into the Unicode characters for the specified 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 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 β€” the column through which spaces are assumed (as if the line were 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 (matching the "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 them to fill out the line. -ffixed-line-length-0 means exactly the same thing as -ffixed-line-length-none.

  • -fno-pad-source β€” by default, fixed-form lines have spaces assumed after the ends of short fixed-form lines (as if padded to that length). that padding is not done if -ffixed-line-length-0, -ffixed-line-length-none or the -fno-pad-source option is used. with any of those options, continued character constants never get implicit spaces appended to them to fill out the line. πŸŽ€
  • -ffree-line-length-n β€” okay so this one sets the column after which characters get ignored in your typical free-form lines in the source file. The default value is 132. And n can be none, meaning the entire line is meaningful β€” no cap, no limits, main character energy ✨. Also -ffree-line-length-0 means the same thing as -ffree-line-length-none, so basically they're twins πŸ’…
  • -fmax-identifier-length=n β€” specify the max allowed identifier length, bestie. Typical values are 31 (that's Fortran 95) and 63 (Fortran 2003 and later). Pick your era πŸŽ€
  • -fimplicit-none β€” says that no implicit typing is allowed, unless explicit IMPLICIT statements override it. It's literally the equivalent of adding implicit none to the start of every procedure. No surprises, no mystery variables, we love a clean slate 🫢
  • -fcray-pointer β€” enables the Cray pointer extension, which gives you C-like pointer functionality. Retro but slay πŸ’œ
  • -fopenacc β€” enables the OpenACC extensions 🌈 This includes OpenACC !$acc directives in free form, plus 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. The whole package, no crumbs πŸ”₯
  • -fopenmp β€” enables the OpenMP extensions ✨ This includes OpenMP !$omp directives in free form, plus c$omp, *$omp and !$omp directives in fixed form, !$ conditional compilation sentinels in free form, and c$, *$ and !$ sentinels in fixed form. When linking, it arranges for the OpenMP runtime library to be linked in. Also important: the option -fopenmp implies -frecursive. Two for one, iconic πŸ‘‘
  • -fno-range-check β€” disables range checking on results of simplification of constant expressions during compilation. Example time: normally GNU Fortran gives you an error at compile time when it simplifies a = 1. / 0. With this option, no error gets given, and a gets assigned the value +Infinity. If an expression evaluates to a value outside the relevant range of [-HUGE():HUGE()], then the expression gets replaced by -Inf or +Inf as appropriate. Similarly, DATA i/Z'FFFFFFFF'/ will 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. It's giving chaos but make it deterministic πŸ’€
  • -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. And ngl, unlike -finteger-4-integer-8, it does not promote variables with explicit kind declaration. Different behaviour, don't mix them up πŸ“
  • -fdefault-real-8 β€” sets the default real type to an 8 byte wide type. This option 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. 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. This option 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. And 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. This option 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. And 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 at all. This option is the one that 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. The vibe check enforcer πŸŽ€
  • -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. > bestie, please use this option 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. Not a casual little flag, 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 affect 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 β€” and this is the plot twist β€” -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. Lots of lore here, iykyk πŸ’…
  • -std=std β€” specify the standard to which the program is expected to conform, which 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. 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. And heads up: 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. Retired, but not forgotten πŸ™ˆ
  • -ftest-forall-temp β€” enhances test coverage by forcing most forall assignments to use temporary. Tiny flag, big test vibes 🧚

✨ Enable and customize preprocessing ✨

Okay so many Fortran compilers, including GNU Fortran, let you pass the source code through a C preprocessor (that's 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 the traditional mode. 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. And to disable preprocessing on files where the preprocessor is run automatically, use -nocpp. Simple πŸ’…

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. Bestie, this one trips people up constantly 😭

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. 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__. Little conditional-compilation cuties πŸŽ€

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). Niche, but noted ✨

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. Pro tip energy πŸ’œ
  • -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. Detective mode activated πŸ”

  • -dD β€” it's giving -dM energy but make it two degrees different: it does not include the predefined macros, and it spits out both the "#define" directives and the result of preprocessing. Both flavours of output land in the standard output file. πŸ’…
  • -dN β€” literally -dD but it only emits the macro names, not their expansions. no notes.
  • -dU β€” like dD, except it only outputs macros that actually get expanded, or whose definedness gets tested in preprocessor directives. the output is delayed until the macro is used or tested (so dramatic, so delayed πŸ’…), and '#undef' directives also get output for macros that were tested but undefined at that moment.
  • -dI β€” outputs '#include' directives on top of the preprocessing result. slay.
  • -fworking-directory β€” turns on generation of linemarkers in the preprocessor output that let the compiler know the current working directory at the time of preprocessing. πŸ—‚οΈ When it's on, the preprocessor emits, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC then uses this directory β€” when it shows up 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 stop it with the negated form -fno-working-directory. And heads up: if the -P flag is present in the command line, this option has no effect, since no "#line" directives are emitted whatsoever. periodt.
  • -idirafter dir β€” search dir for include files, but do it after all 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 β€” use dir as a subdirectory of the directory containing target-specific C++ headers.
  • -iprefix prefix β€” specify prefix as the prefix for subsequent -iwithprefix options. If the prefix represents a directory, bestie you should include the final '/'. πŸŽ€
  • -isysroot dir β€” this one is like the --sysroot option, but it applies only to header files. See the --sysroot option for more info.
  • -iquote dir β€” search dir only for header files requested with "#include "file""; they are not searched for "#include <file>", and this happens 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. πŸ’–
  • -isystem dir β€” search 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 the standard system directories get. If dir begins with "=", then the "=" gets replaced by the sysroot prefix; see --sysroot and -isysroot. ✨
  • -nostdinc β€” do not search the standard system directories for header files. Only the directories you specified with -I options get searched (and the directory of the current file, if appropriate). that's it, that's the list. πŸ’…
  • -undef β€” do not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined, though. so they stay.
  • -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. iconic.
  • -A-predicate=answer β€” cancel an assertion with the predicate predicate and answer answer.
  • -C β€” do not discard comments. All comments get passed through to the output file, except for comments in processed directives, which are deleted along with the directive.

bestie you have to 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.

On top of the side-effects of the -C option, -CC 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.
  • -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.

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 like 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'name(args...)=definition'"

-D and -U options are processed in the order they are given on the command line. All -imacros file and -include file options are processed after all -D and -U options. iykyk.

  • -H β€” print the name of each header file used, on top of other normal activities. Each name is indented to show how deep in the '#include' stack it is. the indent is the whole vibe check. πŸŒ€
  • -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. πŸ’…
  • -Uname β€” cancel any previous definition of name, either built in or provided with a -D option.

✨ Options to request or suppress errors and warnings ✨

Okay so quick lore drop. πŸ”₯

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 help with debugging, but it will not produce any compiled output. πŸ’€

Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there's likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. 🫢

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.

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.
  • -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. just vibes and validation. ✨
  • -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. 😀

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

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. no soft launch here.
  • -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
    • -Wundefined-do-loop

yep, that's the whole roster. πŸ’…

  • -Waliasing β€” warn 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)

like bestie, you passed the same variable as in and out?? the audacity. 😭

  • -Wampersand β€” warn 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. 🌸
  • -Warray-temporaries β€” warn about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries. πŸŽ€
  • -Wc-binding-type β€” bestie, this one yells at you if a variable might not be C interoperable 🫠 like specifically when you declared it with an intrinsic type using the default kind instead of a kind parameter that the ISO_C_Binding intrinsic module defines for C interoperability. Lowkey implied by -Wall.
  • -Wcharacter-truncation β€” warns you when a character assignment is gonna truncate the string you're assigning. the disrespect πŸ’€
  • -Wline-truncation β€” warns when a source code line is gonna get truncated. implied by -Wall. and for free-form source code, the default is -Werror=line-truncation, so truncations get reported as an error, not a cute little warning. no cap.
  • -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 may be problematic. currently that includes -Wcompare-reals, -Wunused-parameter and -Wdo-subscript. it's giving "let me tell you about your choices" energy.
  • -Wfrontend-loop-interchange β€” warns when -ffrontend-loop-interchange is being used to perform loop interchanges.
  • -Wimplicit-interface β€” warns if a procedure gets called without an explicit interface. ⚠️ but heads up: this only checks that an explicit interface is present. it does not check that the declared interfaces are consistent across program units. so don't get too comfortable.
  • -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. the way math just gets chopped 😭
  • -Wintrinsics-std β€” warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (the one picked 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. slay.
  • -Wno-overwrite-recursive β€” do not warn when -fno-automatic is used with -frecursive. real talk: recursion will be broken if the relevant local variables do not have the attribute AUTOMATIC explicitly declared. but 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 show up πŸ‘€ while technically legal, these usually mean an error has been made. right now it produces a warning 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 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 β€” 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 will cause a warning to be issued if a tab is encountered. note: -Wtabs is active for -pedantic, -std=f95, -std=f2003, -std=f2008, -std=f2018 and -Wall. the tab is on thin ice fr πŸ’…
  • -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 which 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 to get calls later resolved to the desired intrinsic/procedure. implied by -Wall. naming drama, iconic.
  • -Wuse-without-only β€” warns if a "USE" statement has no "ONLY" qualifier and thus implicitly imports all public entities of the used module. the way that module just dumps everything on you πŸ™ˆ
  • -Wunused-dummy-argument β€” warns about unused dummy arguments. implied by -Wall.
  • -Wunused-parameter β€” okay so contrary to gcc's meaning of -Wunused-parameter, gfortran's implementation of this option does not warn about unused dummy arguments (that's -Wunused-dummy-argument's job), but 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. this warning can be turned off via -Wno-align-commons. see also -falign-commons.
  • -Wfunction-elimination β€” warns if any calls to impure functions are eliminated by the optimizations enabled by the -ffrontend-optimize option. 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 the 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.
  • -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. the loop that never was πŸ’€
  • -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 that the statement is actually executed. cases like:
real a(3)
do i=1,4
  if (condition(i)) then
    a(i) = 1.2
  end if
end do

this option is implied by -Wextra.

  • -Werror β€” turns all warnings into errors. periodt. πŸ”₯
some of these have no effect when compiling programs written in Fortran. shrug πŸ’

πŸ›βœ¨ 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. detective mode, activated πŸ”

  • -fdump-fortran-original β€” outputs the internal parse tree after translating the source program into internal representation. this one is mostly useful for debugging the GNU Fortran compiler itself. the output generated by this option might change between releases, and it may also generate internal compiler errors for features which have only recently been added. so, yk, use with love πŸ’–
  • -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, and it 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, and it 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 names of those internal variables then start 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, and it 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
    • 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.

The first three exceptions β€” invalid, zero, and overflow β€” often mean something is genuinely wrong, bestie, like not "oops lol" wrong but actual serious errors territory πŸ’€. And unless your program has actual provisions for dealing with those exceptions, turning traps on for those three is probably a good idea ngl.

If you use the option more than once on the command line, the lists get joined together: "ffpe-trap="list1 "ffpe-trap="list2 is equivalent to "ffpe-trap="list1,list2. No cap.

Heads up though β€” once an exception is enabled it cannot be disabled. There's no negative form. It's giving πŸšͺ once you're in, you're in.

Also like, many if not most floating point operations incur loss of precision from rounding, so ffpe-trap=inexact is likely to be super uninteresting in practice. Lowkey pointless. πŸ™ˆ

By default no exception traps are enabled. ✨

  • -ffpe-summary=list β€” this one lets you say which floating-point exceptions get their flag status printed to ERROR_UNIT when you call STOP and ERROR STOP. And list can be either none, all, or a comma-separated list of these exceptions: invalid, zero, overflow, underflow, inexact, and denormal. (go peek at -ffpe-trap for what each exception even means πŸ‘€)

If you use the option more than once on the command line, only the last one counts. Sorry bestie, last one wins πŸ’….

By default, a summary for all exceptions but inexact is shown.

  • -fno-backtrace β€” okay 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 detail: this option only has influence when you're compiling the Fortran main program.

These options change 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's preprocessing Fortran source.

  • -Idir β€” these affect how the INCLUDE directive is interpreted (and also the #include directive of the cpp preprocessor, periodt).

Also note that 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 required by a USE statement. πŸ¦‹

  • -Jdir β€” this one specifies where to put .mod files for compiled modules. It's also 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 sitting in the default location the compiler expects. iykyk

πŸ”— Influencing the linking step 🌈

These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler isn't doing a link step β€” like, if there's no link happening, these do absolutely nothing, bestie.

  • -static-libgfortran β€” on systems that provide libgfortran as both a shared and a static library, this forces the static version to be used. If no shared version of libgfortran was built when the compiler was configured, this option has no effect. πŸ’…
  • -static-libquadmath β€” on systems that provide libquadmath as both a shared and a static library, this forces the static version. If no shared version of libquadmath was built when the compiler was configured, this option has no effect.
Please note that 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 a vibe to skip this one.

🎬 Influencing runtime behavior πŸ’œ

These options affect the runtime behavior of programs compiled with GNU Fortran. So like, the after part. The main character era of your binary. πŸ‘‘

  • -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 has an effect only when used in the main program. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable override the default specified by -fconvert. πŸŽ€

  • -frecord-marker=length β€” specify the length of record markers for unformatted files. Valid values for length are 4 and 8. Default is 4. Okay this is different from previous versions of gfortran, which specified a default record marker length of 8 on most systems. So if you want to read or write files compatible with earlier versions of gfortran, use -frecord-marker=8. πŸ”₯
  • -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. Fr fr, it's a testsuite thing. πŸ§ͺ
  • -fsign-zero β€” when enabled, floating point numbers of value zero with the sign bit set are written as a negative number in formatted output, and treated as negative in the SIGN intrinsic. -fno-sign-zero 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.

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. Cute, right? πŸŽ€

  • -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, as calling COMPLEX or default REAL functions between program parts which were compiled with different calling conventions will break at execution time. πŸ’€ Like, it will just break. At execution time.
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. 😭
  • -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, 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 are experimenting with issues such as integration of GNU Fortran into existing system environments (vis-Γ -vis existing libraries, tools, and so on). πŸ™ˆ

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

Note that just because the names match does not mean that 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. 🫢

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. 😭 Not the drama you want, bestie.

In future versions of GNU Fortran we're hoping to fix up all the naming and linking drama so that debugging always Just Works with the names you actually wrote in your source β€” even when the linker sees mangled versions of them (mangling exists so you don't accidentally link two procedures with incompatible interfaces together, bestie, it's protective πŸ’…).


  • -fsecond-underscore β€” okay so by default GNU Fortran slaps one underscore on the end of external names. With this option? Names that already have underscores get two underscores, and external names with no underscores still get just one. GNU Fortran also tacks two underscores onto internal names that contain underscores, so they don't collide with external names. 🫢

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

Otherwise, with this flag 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 g77 and f2c compatibility, and it's implied whenever you use -ff2c.

  • -fcoarray=<keyword> β€” pick your coarray era:
    • none β€” coarrays? never heard of her πŸ’€ Support is disabled; using coarray declarations and image-control statements gives you a compile-time error. (This is the default.)
    • single β€” single-image mode, so num_images() is literally always one.
    • 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 is a comma-delimited list of these keywords. Prefix a check with no- to switch it off if a previous specification had turned it on. πŸ•΅οΈβ™€οΈ
    • all β€” enable all run-time test of -fcheck.
    • array-temps β€” warns at run time when a temporary array had to be generated for passing an actual argument. This info is sometimes handy for optimization, so you can avoid making those temporaries at all.
Note: the warning only prints 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 makes sure all string lengths are equal for character array constructors without an explicit typespec. ✨ Some checks need -fcheck=bounds to be set for the compilation of the main program too.
Note: in the future this might cover other forms of checking as well, e.g. checking substring references.
  • do β€” run-time checks for invalid modification of loop iteration variables.
  • mem β€” run-time checks for memory allocation.
Note: this option does not affect explicit allocations using the "ALLOCATE" statement β€” those are always checked, no cap.
  • pointer β€” run-time checks for pointers and allocatables.
  • recursion β€” run-time checks for recursively called subroutines and functions that aren't marked as recursive. Also peep -frecursive.
Note: this check does not work for OpenMP programs, and it's disabled if you use it together with -frecursive and -fopenmp.

Example: say you've got a file foo.f90, then this command

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

compiles the file with all the checks enabled as specified above, except the warnings for generated array temporaries. πŸŽ€

  • -fbounds-check β€” deprecated alias for -fcheck=bounds. She's retired, bestie, use the new one.
  • -ftail-call-workaround
  • -ftail-call-workaround=n β€” some C interfaces to Fortran code straight-up violate the gfortran ABI by omitting the hidden character length arguments as described in [see the original cross-reference]. 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 bare -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, crashes included, from insufficient stack space.

It is very strongly recommended to fix the code in question instead. πŸ™ The -fc-prototypes-external option can generate prototypes that conform to gfortran's ABI, for you to drop into 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, disables this option.

Default is currently -ftail-call-workaround; this will change in future releases.

  • -fcheck-array-temporaries β€” deprecated alias for -fcheck=array-temps.
  • -fmax-array-constructor=n β€” raises the upper limit permitted in array constructors. The code below needs 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'll be put on the stack; if you exceed that size, static memory gets 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 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 as possible. Code compiled with this option is likely to be incompatible with code compiled without it, and may also run slower. Trade-off queen, but mind the vibes. πŸ’€
  • -frepack-arrays β€” sometimes GNU Fortran passes assumed shape array sections via a descriptor describing a noncontiguous chunk of memory. This option adds code to the function prologue that repacks the data into a contiguous block at runtime.

Result: faster accesses to the array. But it can add significant overhead to the function call, especially when the data you passed is noncontiguous. ✨

  • -fshort-enums β€” here for interoperability with C code compiled with the -fshort-enums option. It makes GNU Fortran choose the smallest "INTEGER" kind that a given enumerator set will fit in, and give all 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, or as an argument to a procedure that doesn't have an explicit interface, the argument may have to be packed β€” as in, put into contiguous memory. Like the call to "foo" here:
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. That unlocks more optimization, at the cost of bigger code size.

-finline-arg-packing is implied by any of the -O options β€” except when you're optimizing for size via -Os. If your code has a very large number of arguments that need packing, code size and compilation time may get excessive. If that's happening, it may be better to disable this option. You can find instances of packing 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 β€” as long as the size of the matrices involved is larger than a given limit (see -fblas-matmul-limit). This may be worth it if you've got an optimized vendor BLAS library lying around. You'll have to specify the BLAS library 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 gets performed by calls to BLAS functions, while everything else is handled by gfortran's internal algorithms. If the matrices involved aren't square, the size comparison is done 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. That may increase code size if the size of the matrix can't be determined at compile time, since code for both cases gets generated. Setting "-finline-matmul-limit=0" disables inlining in all cases. Setting this option with a value of n produces inline code for matrices with size up to n. If the matrices involved 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" can be used to change this value. πŸ‘‘

  • -frecursive β€” bestie, this one lets you do indirect recursion by forcing every single local array to live on the stack. But heads up: you cannot pair this with -fmax-stack-var-size= or -fno-automatic. They do not get along. Pick a lane πŸ’…
  • -finit-local-zero
  • -finit-derived
  • -finit-integer=n
  • -finit-real=<zero|inf|-inf|nan|snan>
  • -finit-logical=<true|false>
  • -finit-character=n β€” okay so this whole init gang is about auto-filling your local variables so they're not just sitting there feral and undefined ✨

The -finit-local-zero option tells the compiler: initialize local INTEGER, REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER variables to a string of null bytes. Iconic, no notes.

But if you want to be extra specific, there are finer-grained options, and they're giving main character customization energy:

  • -finit-integer=n
  • -finit-real=<zero|inf|-inf|nan|snan> β€” this one also initializes the real and imaginary parts of local COMPLEX variables, fr fr
  • -finit-logical=<true|false>
  • -finit-character=n (where n is an ASCII character value)

With -finit-derived, components of derived type variables get initialized according to these flags too. And components whose type isn't covered by an explicit -finit-* flag? They get treated like we described above with -finit-local-zero. Everyone gets an invite to the party πŸŽ€

Lowkey important: these options do not initialize - objects with the POINTER attribute - allocatable arrays - variables that appear in an EQUIVALENCE statement (and the manpage says these limitations may be removed in future releases, so πŸ’€ maybe someday)

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 bestie, be careful: compile-time optimizations may convert them into quiet NaN, and trapping needs to be enabled (e.g. via -ffpe-trap). That's a real gotcha, not me being dramatic 😭

The -finit-integer option 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. So don't go feral with huge numbers, bestie.

Finally, note that enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables. It's giving "I fixed it by covering it up" but make it compiler πŸ’œ

  • -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 just increases performance (slay). BUT β€” if a COMMON block is not declared with consistent data types everywhere, this padding can cause trouble, and -fno-align-commons can be used to disable automatic alignment. Use the same form of this option for all files that share a COMMON block, okay? Consistency is the vibe. And to avoid potential alignment issues in COMMON blocks, it's recommended to order objects from largest to smallest πŸ¦‹
  • -fno-protect-parens β€” by default the parentheses in expressions are honored for all optimization levels, so the compiler doesn't do any re-association. Respect the parentheses, they said. But using -fno-protect-parens lets the compiler 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. So -Ofast is the one friend that talks over the parentheses πŸ™ˆ
  • -frealloc-lhs β€” an allocatable left-hand side of an intrinsic assignment gets automatically (re)allocated if it's either unallocated or has a different shape. It's giving self-healing. This option is enabled by default except when -std=f95 is given. See also -Wrealloc-lhs πŸ‘‘
  • -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. The compiler said "I've seen this one before" and moved on. Note: this option only works if -ffrontend-optimize is in effect ⭐

  • -ffrontend-optimize β€” this option performs front-end optimization, based on manipulating parts of the Fortran parse tree. Enabled by default by any -O option except -O0 and -Og. The optimizations it brings to the function are:
    • 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. Choose your fighter ✨

  • -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. It's niche but it's doing its thing 🌸

🌍 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. So no secret env vars to unlock, bestie β€” the vibes come from gcc entirely πŸ€·β€β™€οΈ


πŸ› BUGS πŸ›

For instructions on reporting bugs, see <file:///usr/share/doc/gcc-13/README.Bugs> 🫢


πŸ‘€ 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, together again πŸ’–


✍️ AUTHOR ✍️

See the Info entry for gfortran for contributors to GCC and GNU Fortran. Shoutout to the contributors, we love them πŸ’œ


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.

and that's a wrap on the whole page, bestie!! πŸŽ‰ this edition is from gcc-13, dated 2026-09-10, and it's officially GFORTRAN(1). go forth and compile something iconic, you absolute icon πŸ‘‘πŸ’…βœ¨

πŸ“¦ where this page comes from