GFORTRAN(1)

πŸ“¦
version 15.3.1 Β· 3 versions
, in fedora 44

GFORTRAN(1) πŸ’…βœ¨

okay bestie, listen β€” this is the GNU manual page for gfortran, and it lives in section 1 of the manual (the "user commands" section, iykyk). grab a snack, we're going in πŸ“


🌸 NAME 🌸

gfortran β€” the GNU Fortran compiler. that's it, that's the name, she's a compiler and she's iconic πŸ‘‘


✨ SYNOPSIS ✨

here's the vibe-check of how you actually call her:

gfortran [-c|-S|-E]
         [-g] [-pg] [-Olevel]
         [-Wwarn...] [-pedantic]
         [-Idir...] [-Ldir...]
         [-Dmacro[=defn]...] [-Umacro]
         [-foption...]
         [-mmachine-option...]
         [-o outfile] infile...
lowkey important: this is just the most useful options, okay? the rest are further down. we don't gatekeep here, but we do scroll πŸ“œ

πŸ¦‹ DESCRIPTION πŸ¦‹

gfortran supports all the options supported by the gcc command. but bestie β€” only the options that are specific to GNU Fortran get documented on this page. the rest live with gcc, not here πŸ’–

so here's the tea: all GCC and GNU Fortran options are accepted both by gfortran and by gcc (and honestly by any other drivers built at the same time, like g++). why? because adding GNU Fortran to the GCC distribution is what makes all of those relevant drivers accept GNU Fortran options. it's giving "one big happy compiler family" 🫢

in some cases, options have a positive and a negative form β€” so the negative form of -ffoo would be -fno-foo. and this manual documents only one of these two forms: whichever one is not the default. no cap, that's just how it is ⭐


πŸ‘‘ OPTIONS πŸ‘‘

okay so here's the whole rundown of every option that's specific to GNU Fortran, grouped by type. the actual explanations are in the sections that follow this one β€” this part is the menu, the appetizer, the little preview reel πŸŽ€

🌈 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
-fopenmp-allocators -fopenmp-simd -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 -funsigned

🌸 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 -fdebug-aux-vars -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-intrinsics[=<minloc,maxloc>] -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

πŸ’… Developer Options πŸ’…

-fdump-fortran-global -fdump-fortran-optimized
-fdump-fortran-original -fdump-parse-tree -save-temps

🌟 Options controlling Fortran dialect 🌟

these are the ones that decide which flavour of Fortran the compiler is willing to accept. she has opinions, and honestly? valid πŸ’…

  • -ffree-form
  • -ffixed-form β€” these two set the layout your source file uses. free form layout was introduced in Fortran 90 (the modern era, the glow-up ✨). fixed form is the traditional one, used by older Fortran programs. and if you specify neither of them? the source form gets determined by the file extension. she'll just know. trust πŸ¦‹
  • -fall-intrinsics β€” this makes all intrinsic procedures get accepted, including the GNU-specific extensions. super useful alongside -std= when you wanna force standard compliance but still get access to the full range of intrinsics gfortran has. the consequence tho: -Wintrinsics-std gets ignored, and no user-defined procedure with the same name as any intrinsic gets called β€” unless it's explicitly declared EXTERNAL. periodt.
  • -fallow-argument-mismatch β€” so some code calls external procedures with mismatches between the calls and the procedure definition, or mismatches between different calls. that code is nonconforming, and it usually gets flagged with an error. this option degrades that error into a warning β€” and that warning can only be disabled by disabling all warnings via -w. only a single occurrence per argument gets flagged by this warning, fyi. also: -fallow-argument-mismatch is implied by -std=legacy.
🚨 bestie, using this option is strongly discouraged. you can write standard-conforming code that allows different types of arguments by using an explicit interface and TYPE(*). do that instead, fr fr.
  • -fallow-invalid-boz β€” a BOZ literal constant can only show up in a limited number of contexts in standard conforming Fortran. this option degrades an error condition into a warning, and lets a BOZ literal constant appear in places where the Fortran standard would otherwise prohibit its use. living dangerously, but make it a warning πŸ™ˆ
  • -fd-lines-as-code
  • -fd-lines-as-comments β€” these enable special treatment for lines beginning with "d" or "D" in fixed form sources. give it -fd-lines-as-code and those lines are treated as if the first column contained a blank. give it -fd-lines-as-comments and they're treated as comment lines. pick your fighter πŸ₯Š
  • -fdec β€” DEC compatibility mode, babes. enables extensions and other features that mimic the default behavior of older compilers (such as DEC). these features are nonstandard and should be avoided at all costs. for the details on GNU Fortran's implementation of these extensions, see the full documentation πŸ“š

other flags this switch enables 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 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. yes, really 🌈
  • -fdec-structure β€” enables DEC STRUCTURE and RECORD, plus 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. no cap, use the derived types πŸ’œ
  • -fdec-intrinsic-ints β€” enables B/I/J/K kind variants of existing integer functions (e.g. BIAND, IIAND, JIAND, etc...). for the complete list of intrinsics, see Intrinsic Procedures.
  • -fdec-math β€” obsolete flag, bestie. the whole purpose of this option was to enable legacy math intrinsics like COTAN and degree-valued trigonometric functions (e.g. TAND, ATAND, etc...) for compatibility with older code. this option is no longer operable. the trigonometric functions are now either part of Fortran 2023 or GNU extensions. she's retired, respect her legacy πŸ’€
  • -fdec-static β€” enables DEC-style STATIC and AUTOMATIC attributes, so you can explicitly specify the storage of variables and other objects.
  • -fdec-include β€” enables parsing of INCLUDE as a statement, in addition to parsing it as an INCLUDE line. and when it's parsed as an INCLUDE statement, INCLUDE does not have to be on a single line β€” it can use line continuations. glow-up unlocked ✨
  • -fdec-format-defaults β€” enables format specifiers F, G and I to be used without width specifiers; default widths get used instead.
  • -fdec-blank-format-item β€” enables a blank format item at the end of a format specification, i.e. nothing following the final comma. a little "and then nothing" moment, we love that for her πŸŽ€
  • -fdollar-ok β€” allows $ as a valid non-first character in a symbol name. symbols that start with $ are rejected, since it's unclear which rules to apply to implicit typing β€” different vendors implement different rules, messy πŸ’…. using $ in IMPLICIT statements is also rejected.
  • -fbackslash β€” changes how backslashes in string literals get interpreted: instead of a single backslash character, you get "C-style" escape characters. here's what expands: \a, \b, \f, \n, \r, \t, \v, \\, and \0 β€” which 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 corresponding to the specified code points. all other combinations of a character preceded by \ are unexpanded. that's the whole menu, slay πŸ“
  • -fmodule-private β€” sets the default accessibility of module entities to PRIVATE. use-associated entities are not accessible unless they're explicitly declared as PUBLIC. exclusive behaviour, honestly iconic πŸ‘‘
  • -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 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 (which corresponds to "extended-source" options in some popular compilers). n may also be none, meaning the entire line is meaningful and that continued character constants never have implicit spaces appended to them to fill out the line. and heads up: -ffixed-line-length-0 means the same thing as -ffixed-line-length-none 🌈


more coming, bestie β€” don't go anywhere πŸ’–

  • -fno-pad-source β€” okay so by default, fixed-form lines have spaces assumed after the ends of short fixed-form lines, like they got padded to that length. This is not done if you use -ffixed-line-length-0, -ffixed-line-length-none, or this very option -fno-pad-source. With any of those options, continued character constants never have implicit spaces appended to them to fill out the line. periodt πŸ’…
  • -ffree-line-length-n β€” set the column after which characters are ignored in typical free-form lines in the source file. The default value is 132. n may be none, meaning that the entire line is meaningful. -ffree-line-length-0 means the same thing as -ffree-line-length-none. slay ✨
  • -fmax-identifier-length=n β€” specify the maximum allowed identifier length. Typical values are 31 (Fortran 95) and 63 (Fortran 2003 and later). got it, bestie? πŸ’œ
  • -fimplicit-none β€” specify that no implicit typing is allowed, unless overridden by explicit IMPLICIT statements. This is the equivalent of adding implicit none to the start of every procedure. iconic behavior 🫢
  • -fcray-pointer β€” enable the Cray pointer extension, which provides C-like pointer functionality. fancy pointer vibes πŸ‘‘
  • -fopenacc β€” enable handling of OpenACC directives !$acc in free-form Fortran and !$acc, c$acc and *$acc in fixed-form Fortran. When -fopenacc is specified, the compiler generates accelerated code according to the OpenACC Application Programming Interface v2.6 https://www.openacc.org. This option implies -pthread, and thus is only supported on targets that have support for -pthread. The option -fopenacc implies -frecursive. accelerated bestie moment πŸ”₯
  • -fopenmp β€” enable handling of OpenMP directives !$omp in Fortran. It additionally enables the conditional compilation sentinel !$ in Fortran. In fixed source form Fortran, the sentinels can also start with c or *. When -fopenmp is specified, the compiler generates parallel code according to the OpenMP Application Program Interface v4.5 https://www.openmp.org. This option implies -pthread, and thus is only supported on targets that have support for -pthread. -fopenmp implies -fopenmp-simd and -frecursive. parallel queen πŸ‘‘
  • -fopenmp-allocators β€” enables handling of allocation, reallocation and deallocation of Fortran allocatable and pointer variables that are allocated using the !$omp allocators and !$omp allocate constructs. Files containing either directive have to be compiled with this option in addition to -fopenmp. Additionally, all files that might deallocate or reallocate a variable that has been allocated with an OpenMP allocator have to be compiled with this option. This includes intrinsic assignment to allocatable variables when reallocation may occur and deallocation due to either of the following: end of scope, explicit deallocation, intent(out), deallocation of allocatable components etc. Files not changing the allocation status or only for components of a derived type that have not been allocated using those two directives do not need to be compiled with this option. Nor do files that handle such variables after they have been deallocated or allocated by the normal Fortran allocator. so many rules but we love that for us πŸ’–
  • -fopenmp-simd β€” enable handling of OpenMP's simd, declare simd, declare reduction, assume, ordered, scan and loop directive, and of combined or composite directives with simd as constituent with !$omp in Fortran. It additionally enables the conditional compilation sentinel !$ in Fortran. In fixed source form Fortran, the sentinels can also start with c or *. Other OpenMP directives are ignored. Unless -fopenmp is additionally specified, the loop region binds to the current task region, independent of the specified bind clause. simd but make it fashion ✨
  • -fno-range-check β€” disable range checking on results of simplification of constant expressions during compilation. For example, GNU Fortran gives an error at compile time when simplifying a = 1. / 0. With this option, no error is given and a is assigned the value +Infinity. If an expression evaluates to a value outside of the relevant range of ["-HUGE()":HUGE()], then the expression is replaced by -Inf or +Inf as appropriate. Similarly, DATA i/Z'FFFFFFFF'/ results in an integer overflow on most systems, but with -fno-range-check the value "wraps around" and i is initialized to -1 instead. chaos mode activated πŸ’€
  • -fdefault-integer-8 β€” set 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. thicc integers πŸ“
  • -fdefault-real-8 β€” set the default real type to an 8 byte wide type. This option 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. Unlike -freal-4-real-8, fdefault-real-8 does not promote variables with explicit kind declarations. real ones know πŸ’…
  • -fdefault-real-10 β€” set the default real type to an 10 byte wide type. This option 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-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. ten bytes of main character energy πŸ‘‘
  • -fdefault-real-16 β€” set the default real type to an 16 byte wide type. This option 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-16, DOUBLE PRECISION and double real constants are not promoted. Unlike -freal-4-real-16, fdefault-real-16 does not promote variables with explicit kind declarations. sixteen? go off 🌈
  • -fdefault-double-8 β€” set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type. Do nothing if this is already the default. 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. the great preventer πŸ’–
  • -finteger-4-integer-8 β€” promote all INTEGER(KIND=4) entities to an INTEGER(KIND=8) entities. If KIND=8 is unavailable, then an error is issued. This option 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. Inspection of the intermediate representation of the translated Fortran code, produced by -fdump-tree-original, is suggested. be careful bestie 😭
  • -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 is 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. kind conversion chaos but make it couture πŸ’…
  • -std=std β€” specify the standard to which the program is expected to conform, which may be one of f95, f2003, f2008, f2018, f2023, 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 are 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 nonstandard programs. The f95, f2003, f2008, f2018, and f2023 values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008, Fortran 2018 and Fortran 2023 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. -std=f202y acts as an alias for -std=f2023 and enables proposed features for testing Fortran 202y. As the Fortran 202y standard develops, implementation might change or the experimental new features might be removed. standard issue but make it sassy ⭐
  • -ftest-forall-temp β€” enhance test coverage by forcing most forall assignments to use temporary. test queen 🧚
  • -funsigned β€” allow the experimental unsigned extension. experimental, we love a risk πŸ™ˆ

✨ Enable and customize preprocessing ✨

okay so bestie, here's the tea β˜• β€” lots of Fortran compilers (GNU Fortran included) let you run your source through a C preprocessor (CPP, aka the Fortran preprocessor or FPP for short) so you can do conditional compilation. With GNU Fortran specifically? That's the GNU C Preprocessor, chillin' in traditional mode. πŸ’…

On systems with case-preserving file names, the preprocessor gets summoned automatically when your filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. Wanna manually invoke it on literally any file? Use -cpp. Wanna switch it off on files where it runs automatically? Use -nocpp. easy. ✨

If a preprocessed file pulls in another file via the Fortran "INCLUDE" statement, heads up: that included file is not preprocessed. 😭 To preprocess included files, use the equivalent preprocessor statement #include instead.

When GNU Fortran runs the preprocessor, __GFORTRAN__ is defined. And you can use __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to figure out the compiler's version. See Top,,Overview,cpp,The C Preprocessor for the deets. πŸ¦‹

GNU Fortran also supports a bunch of "INTEGER" and "REAL" kind types on top of the ones the Fortran standard requires β€” though whether any given kind type is available is architecture dependent, so vibe check your target first. 🫢 These predefined preprocessor macros let you conditionally include code for those extra kind types: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__.

Now, CPP is the de facto standard for preprocessing Fortran code, but Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines something called Conditional Compilation β€” which is not widely used and not directly supported by the GNU Fortran compiler. so like, don't come for her about that one. πŸ™ˆ

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

  • -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

shows all the predefined macros. πŸ‘‘

  • -dD β€” Like -dM except in two respects: it does not include the predefined macros, and it outputs both the "#define" directives and the result of preprocessing. Both kinds of output go to the standard output file.
  • -dN β€” Like -dD, but emit only the macro names, not their expansions.
  • -dU β€” Like dD except that only macros that are expanded, or whose definedness is tested in preprocessor directives, are output; the output is delayed until the use or test of the macro; and '#undef' directives are also output for macros tested but undefined at the time.
  • -dI β€” Output '#include' directives in addition to the result of preprocessing.
  • -fworking-directory β€” Enable generation of linemarkers in the preprocessor output that let the compiler know the current working directory at the time of preprocessing. When this option is enabled, the preprocessor emits, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC uses this directory, when it is 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 this can be inhibited with the negated form -fno-working-directory. If the -P flag is present in the command line, this option has no effect, since no "#line" directives are emitted whatsoever. πŸ’€
  • -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 "=" is 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, you should include the final '/'.
  • -isysroot dir β€” This option is like the --sysroot option, but applies only to header files. See the --sysroot option for more information.
  • -iquote dir β€” Search 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 "=" is 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. Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. If dir begins with "=", then the "=" is replaced by the sysroot prefix; see --sysroot and -isysroot.
  • -nostdinc β€” Do not search the standard system directories for header files. Only the directories you have specified with -I options (and the directory of the current file, if appropriate) are searched.
  • -undef β€” Do not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined. ✨
  • -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 does not use shell special characters.
  • -A-predicate=answer β€” Cancel an assertion with the predicate predicate and answer answer.
  • -C β€” Do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are 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.
  • -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 is truncated by embedded newline characters.

If you are 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 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. All -imacros file and -include file options are processed after all -D and -U options.

  • -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.
  • -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 is sent to a program that 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 let's talk diagnostics, bestie, because these are literally your besties when stuff goes wrong. 🫢

Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler keeps processing the program in an attempt to report further errors to aid in debugging, but it does not produce any compiled output. πŸ’€

Warnings are diagnostic messages that report constructions that are not inherently erroneous but that 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. πŸŽ€

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. πŸ¦‹
  • -fsyntax-only β€” bestie, this one is the ✨vibe check✨ only. It checks your code for syntax errors but does NOT actually compile it. It does generate module files for each module present in the code, but no other output file. So like, it's giving "am I valid?" energy without the full build. 🫢
  • -Wpedantic, -pedantic β€” issues warnings for uses of extensions to Fortran. And -pedantic also applies to C-language constructs where they occur in GNU Fortran source files, like use of \e in a character constant within a directive like "#include". Valid Fortran programs should compile properly with or without this option. But without it, certain GNU extensions and traditional Fortran features are supported too. With it, many of them get rejected. 😭 Some users try to use -pedantic to check programs for conformance. They soon find it doesn't 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, -std=f2018 or -std=f2023.
  • -pedantic-errors β€” like -pedantic, except errors are produced rather than warnings. So it's the same vibe but turned up to 11. πŸ’…
  • -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. Slay. ✨
  • -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 triggers 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)

So yeah, same variable passed to both in and out β€” red flag. 🚩

  • -Wampersand β€” warns about missing ampersand in continued character constants. The warning is given with -Wampersand, -pedantic, -std=f95, -std=f2003, -std=f2008, -std=f2018 and -std=f2023. 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 like, it's doing its best guess. πŸ™ˆ
  • -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. Optimization girlies, this one's for you. πŸ’…
  • -Wc-binding-type β€” warns if a variable might not be C interoperable. In particular, it warns if the variable has been declared using an intrinsic type with default kind instead of using a kind parameter defined for C interoperability in the intrinsic "ISO_C_Binding" module. This option is implied by -Wall. C interoperability is not a vibe, it's a requirement. 😭
  • -Wcharacter-truncation β€” warns when a character assignment truncates the assigned string. Like, you had one job: fit the string. You did not fit the string. πŸ’€
  • -Wline-truncation β€” warns when a source code line is truncated. This option is implied by -Wall. For free-form source code, the default is -Werror=line-truncation such that truncations are reported as error. So in free-form, truncation is not a warning, it's an error by default. No cap. 🚨
  • -Wconversion β€” warns about implicit conversions that are likely to change the value of the expression after conversion. Implied by -Wall. Implicit conversion can be a sneaky little gremlin. πŸ‘€
  • -Wconversion-extra β€” warns about implicit conversions between different types and kinds. This option does not imply -Wconversion. So it's extra, but it doesn't drag its friend along. πŸ’…
  • -Wexternal-argument-mismatch β€” warns about argument mismatches for dummy external procedures. This is implied by -fc-prototypes-external because generation of a valid C23 interface is not possible in such a case. Also implied by -Wall. Mismatch? Not on my watch. 🫢
  • -Wextra β€” enables some warning options for usages of language features that may be problematic. This currently includes -Wcompare-reals, -Wunused-parameter and -Wdo-subscript. Extra! Extra! Read all about it! πŸ“’
  • -Wfrontend-loop-interchange β€” warns when using -ffrontend-loop-interchange for performing loop interchanges. Loop interchange, but make it warned. πŸ”„
  • -Wimplicit-interface β€” warns if a procedure is called without an explicit interface. Note this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units. So it's not a full consistency check, bestie. 😬
  • -Wimplicit-procedure β€” warns if a procedure is called that has neither an explicit interface nor has been declared as "EXTERNAL". Where is the interface? Where is the EXTERNAL? Nowhere? Warning. πŸ’…
  • -Winteger-division β€” warns if a constant integer division truncates its result. As an example, 3/5 evaluates to 0. Math girlies, integer division is not your friend. 😭
  • -Wintrinsics-std β€” warns if gfortran finds a procedure named like an intrinsic not available in the currently selected standard (with -std) and treats it as "EXTERNAL" procedure because of this. -fall-intrinsics can be used to never trigger this behavior and always link to the intrinsic regardless of the selected standard. So if you want the intrinsic no matter what, there's a flag for that. ✨
  • -Wno-overwrite-recursive β€” do not warn when -fno-automatic is used with -frecursive. Recursion is broken if the relevant local variables do not have the attribute "AUTOMATIC" explicitly declared. This option can be used to suppress the warning when it is known that recursion is not broken. Useful for build environments that use -Werror. If you know recursion is fine, you can tell it to chill. 🧘
  • -Wreal-q-constant β€” produces a warning if a real-literal-constant contains a "q" exponent-letter. Q? In this economy? πŸ’€
  • -Wsurprising β€” produces a warning when "suspicious" code constructs are encountered. While technically legal, these usually indicate that an error has been made. This currently produces a warning under the following circumstances:
    • An "INTEGER"-typed "SELECT CASE" construct has a "CASE" that can never be matched as its lower value is greater than its upper value.
    • A "LOGICAL"-typed "SELECT CASE" 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.)

Surprising indeed. Bestie, these are red flags. 🚩

  • -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 causes a warning to be issued if a tab is encountered. Note, -Wtabs is active for -pedantic, -std=f95, -std=f2003, -std=f2008, -std=f2018, -std=f2023 and -Wall. Tabs are not Fortran. They are chaos. πŸ’€
  • -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. This option is implied by -Wall. Underflow? Overflow? In my DO loop? It's more likely than you think. 😭
  • -Wunderflow β€” produces a warning when numerical constant expressions that yield an underflow are encountered during compilation. Enabled by default. Underflow warning is on by default, so it's already watching. πŸ‘€
  • -Wintrinsic-shadow β€” warns if a user-defined procedure or module procedure has the same name as an intrinsic; in this case, an explicit interface or "EXTERNAL" or "INTRINSIC" declaration might be needed to get calls later resolved to the desired intrinsic/procedure. This option is implied by -Wall. Name collision? Not the vibe. πŸ’…
  • -Wuse-without-only β€” warns if a "USE" statement has no "ONLY" qualifier and thus implicitly imports all public entities of the used module. USE with ONLY is the serve. USE without ONLY is the mess. πŸ’€
  • -Wunused-dummy-argument β€” warns about unused dummy arguments. This option is implied by -Wall. Unused dummy argument? Girl, why is it there? πŸ™ˆ
  • -Wunused-parameter β€” contrary to gcc's meaning of -Wunused-parameter, gfortran's implementation of this option does not warn about unused dummy arguments (see -Wunused-dummy-argument), but about unused "PARAMETER" values. -Wunused-parameter is implied by -Wextra if also -Wunused or -Wall is used. So it's not the same as gcc, bestie. Read the label. 😭
  • -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. Padding for alignment? In COMMON? It's giving structural. ✨
  • -Wfunction-elimination β€” warns if any calls to impure functions are eliminated by the optimizations enabled by the -ffrontend-optimize option. This option is implied by -Wextra. Optimization eliminated your impure function call? That's a warning. πŸ”₯
  • -Wrealloc-lhs β€” warns when the compiler might insert code to 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 optimizes reallocation checks away. For instance, when the right-hand side contains the same variable multiplied by a scalar. See also -frealloc-lhs. Hot loops + reallocation = performance tears. Consider (:,:,:). πŸ’…
  • -Wrealloc-lhs-all β€” warns when the compiler inserts code to for allocation or reallocation of an allocatable variable; this includes scalars and derived types. Now with scalars and derived types! The whole family. πŸ‘‘
  • -Wcompare-reals β€” warns when comparing real or complex types for equality or inequality. This option is implied by -Wextra. Comparing floats for equality? In this house? We don't. πŸ’€
  • -Wtarget-lifetime β€” warns if the pointer in a pointer assignment might be longer than the its target. This option is implied by -Wall. Pointer outliving its target? Not the plot twist we wanted. 😭
  • -Wzerotrip β€” warns if a "DO" loop is known to execute zero times at compile time. This option is implied by -Wall. Zero trips? The loop is not looping. πŸ’€
  • -Wdo-subscript β€” warns if an array subscript inside a "DO" loop could lead to an out-of-bounds access even if the compiler cannot prove that 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

This option is implied by -Wextra. Out-of-bounds energy detected. Even if it might not run, the warning is there. 🚨

  • -Werror β€” turns all warnings into errors. All warnings? Errors now. Periodt. πŸ’…

Some of these have no effect when compiling programs written in Fortran. So like, if you're compiling Fortran, some of these flags are just vibes. 😭


🐞 Options for debugging your program 🐞

GNU Fortran has various special options that are used for debugging your program. Debugging era! We love a good debug session. 🫢

  • -fdebug-aux-vars β€” bestie, this one literally renames the internal variables that the gfortran front end makes, so your debugger can actually see them πŸ‘€. The renamed ones start with uppercase letters followed by an underscore. It's giving "let me peek inside the compiler's brain" β€” super useful when you're debugging the compiler's code generation, especially paired with -fdump-tree-original, and also when you turn on debugging of the executable program with -g or -ggdb3. πŸ›
  • -ffpe-trap=list β€” okay so this sets up a list of floating point exception traps to enable. On most systems, if a floating point exception happens and the trap for it is on, a SIGFPE signal gets sent, the program aborts, and you get a core file that's genuinely useful for debugging. πŸ’€

list is a (possibly empty) comma-separated list of either none (which clears the whole set of exceptions to be trapped), or any of these icons:

  • invalid β€” invalid floating point operation, like SQRT(-1.0)
  • zero β€” division by zero
  • overflow β€” overflow in a floating point operation
  • underflow β€” underflow in a floating point operation
  • inexact β€” loss of precision during operation
  • denormal β€” operation performed on a denormal value

The first five correspond to the five IEEE 754 exceptions, 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 indicate serious errors, and unless the program has provisions for dealing with these exceptions, enabling traps for these three is probably a good idea. πŸ‘‘

If the option is used more than once on the command line, the lists are joined: "ffpe-trap="list1 "ffpe-trap="list2 is equivalent to "ffpe-trap="list1,list2.

Note that once enabled an exception cannot be disabled (there's no negative form), except by clearing all traps by specifying none. πŸ™ˆ

Many, if not most, floating point operations incur loss of precision due to rounding, and hence the "ffpe-trap=inexact" is likely to be uninteresting in practice. ngl it's the drama queen of traps, it complains about everything.

By default, no exception traps are enabled.

  • -ffpe-summary=list β€” this one picks a list of floating-point exceptions whose flag status gets printed to ERROR_UNIT when you invoke STOP and ERROR STOP. πŸ“’ list can be either none, all, or a comma-separated list of: invalid, zero, overflow, underflow, inexact and denormal. (Go peep -ffpe-trap for a description of the exceptions β€” same squad.)

If the option is used more than once on the command line, only the last one is used.

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

  • -fno-backtrace β€” when a serious runtime error is encountered, or a deadly signal is emitted (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals that have the action core), the Fortran runtime library tries to output a backtrace of the error. -fno-backtrace disables the backtrace generation. πŸš«πŸ”™ This option only has influence for compilation of the Fortran main program.

These options affect how GNU Fortran searches for files specified by the INCLUDE directive, and where it searches for previously compiled modules. πŸ¦‹

It also affects the search paths used by cpp when it's used to preprocess Fortran source.

  • -Idir β€” these affect interpretation of the INCLUDE directive (as well as of the #include directive of the cpp preprocessor).

Also note that the general behavior of -I and INCLUDE is pretty much the same as of -I with #include in the cpp preprocessor, with regard to looking for header.gcc files and other such things. iykyk ✨

This path is also used to search for .mod files when previously compiled modules are required by a USE statement.

  • -Jdir β€” this option specifies where to put .mod files for compiled modules. It is also added to the list of directories to be searched by a USE statement. 🫢

The default is the current directory.

  • -fintrinsic-modules-path dir β€” this option specifies the location of pre-compiled intrinsic modules, if they're not in the default location expected by the compiler. πŸŽ€

πŸ”— 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. periodt.

  • -static-libgfortran β€” on systems that provide libgfortran as both a shared and a static library, this option 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. πŸ’…
  • -static-libquadmath β€” on systems that provide libquadmath as both a shared and a static library, this option forces the use of 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 me reminding you about legal stuff but here we are

βš™οΈ Influencing runtime behavior βš™οΈ

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

  • -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 that 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. 🎯 This is different from previous versions of gfortran, which specified a default record marker length of 8 on most systems. 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. πŸ§ͺ
  • -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. -fno-sign-zero does not print the negative sign of zero values (or values rounded to zero for I/O) and regards zero as positive number in the SIGN intrinsic for compatibility with Fortran 77. The default is -fsign-zero. 🌸

πŸ› οΈ GNU Fortran Developer Options πŸ› οΈ

GNU Fortran has various special options that are used for debugging the GNU Fortran compiler itself. πŸ‘©β€πŸ’»

  • -fdump-fortran-global β€” output 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 that have only recently been added. πŸ’€
  • -fdump-fortran-optimized β€” output 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 that have only recently been added.
  • -fdump-fortran-original β€” output the internal parse tree after translating the source program into internal representation. This option is 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 that have only recently been added. 🌈
  • -fdump-parse-tree β€” output 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 that have only recently been added.
This option is deprecated; use -fdump-fortran-original instead. 🚨
  • -save-temps β€” store the usual "temporary" intermediate files permanently; name them as auxiliary output files, as specified described under GCC -dumpbase and -dumpdir.
gfortran -save-temps -c foo.F90

preprocesses input file foo.F90 to foo.fii, compiles to an intermediate foo.s, and then assembles to the (implied) output file foo.o, whereas:

gfortran -save-temps -S foo.F

saves the preprocessor output in foo.fi, and then compiles to the (implied) output file foo.s. ✨


🧬 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 that is not the default. You can figure out the other form by either removing no- or adding it. πŸ’…

  • -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. πŸ”₯

so the calling conventions that g77 uses (which, fun fact, were originally implemented in f2c) require that functions returning default REAL actually hand back the C type double, and that functions returning COMPLEX return their values through an extra argument in the calling sequence that points at where the return value should live. Under the default GNU calling conventions, though, those functions just return their results the way they would in GNU C β€” default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. Also, this option implies -fsecond-underscore, unless you explicitly ask for -fno-second-underscore.

This does not affect the generation of code that interfaces with the libgfortran library.

Caution: mixing Fortran code compiled with -ff2c together with code compiled using the default -fno-f2c calling conventions? Not a good idea, bestie. If you call COMPLEX or default REAL functions between program parts that were compiled with different calling conventions, it will break at execution time. πŸ’€
Caution: this also breaks code that passes intrinsic functions of type default REAL or COMPLEX as actual arguments, because the library implementations use the -fno-f2c calling conventions. 😭
  • -fno-underscoring β€” do not transform the 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. Why? For compatibility with code produced by lots of UNIX Fortran compilers. Heads up though: this does not apply to names declared with C binding, or names inside a module.

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

Using -fno-underscoring is not recommended unless you're out here experimenting with things like integrating 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 Fortran statement like

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

is implemented as something akin to the C code:

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. Like, 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 conflicts 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. πŸ’€

Also note that declaring symbols as bind(C) is a more robust way to interface with code written in other languages or compiled with different Fortran compilers than the command-line options documented in this section.

  • -fsecond-underscore β€” by default, GNU Fortran appends an underscore to external names. If this option is used, GNU Fortran appends two underscores to names with underscores and one underscore to names with no underscores.

For example, an external name such as MAX_COUNT is implemented as a reference to the link-time external symbol max_count__, instead of max_count_. This is required for compatibility with g77 and f2c, and is implied by use of the -ff2c option.

This option has no effect if -fno-underscoring is in effect. It is implied by the -ff2c option.

  • -fcoarray=<keyword>
    • none β€” disable coarray support; using coarray declarations and image-control statements produces a compile-time error. (This is the default.)
    • single β€” single-image mode, i.e. num_images() is always one.
    • lib β€” library-based coarray parallelization; a suitable GNU Fortran coarray library such as <http://opencoarrays.org> needs to be linked. Alternatively, GCC's libcaf_single library can be linked, albeit it only supports a single image.
  • -fcheck=<keyword> β€” enable the generation of run-time checks; the argument shall be a comma-delimited list of the following keywords. Prefixing a check with no- disables it if it was activated by a previous specification.
    • all β€” enable all run-time test of -fcheck.
    • array-temps β€” warns at run time when, for passing an actual argument, a temporary array had to be generated. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries.

Note: the warning is only printed once per location.

  • bits β€” enable generation of run-time checks for invalid arguments to the bit manipulation intrinsics.
  • bounds β€” enable generation of 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 that 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 β€” enable generation of run-time checks for invalid modification of loop iteration variables.
  • mem β€” enable generation of run-time checks for memory allocation. Note: this option does not affect explicit allocations using the ALLOCATE statement, which are always checked.
  • pointer β€” enable generation of run-time checks for pointers and allocatables.
  • recursion β€” enable generation of 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

compiles the file with all checks enabled as specified above except warnings for generated array temporaries.

  • -fbounds-check β€” deprecated alias for -fcheck=bounds.
  • -ftail-call-workaround
  • -ftail-call-workaround=n

Some C interfaces to Fortran codes violate the gfortran ABI by omitting the hidden character length arguments as described in. This can lead to crashes because pushing arguments for tail calls can overflow the stack. 😬

To provide a workaround 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 equivalent -ftail-call-workaround 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 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.
  • -fmax-array-constructor=n β€” this option can be used to increase the upper limit permitted in array constructors. The code below 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 β€” this option specifies the size in bytes of the largest array that is put on the stack; if the size is exceeded static memory is used (except in procedures marked as RECURSIVE). Use the option -frecursive to allow for recursive procedures that do not have a RECURSIVE attribute or for parallel programs. Use -fno-automatic to never use the stack.

This option currently only affects local arrays declared with constant bounds, and 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 option makes the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory. If your program uses very large local arrays it is possible that you 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 β€” bestie, this one tells GNU Fortran to pack derived type members as closely as physically possible πŸ’…. Heads up though: code compiled with this is likely to be incompatible with code compiled without it, and it may run slower. So it's giving tradeoffs, not a free win πŸ™ˆ.
  • -frepack-arrays β€” sometimes GNU Fortran passes assumed shape array sections via a descriptor describing a noncontiguous</> area of memory. This option adds code to the function prologue to repack that data into one contiguous block at runtime ✨.

The vibe: faster accesses to the array. The catch: it can introduce significant overhead to the function call, especially when the passed data is noncontiguous. It's giving "pay now or pay later" πŸ’€.

  • -fshort-enums β€” this one exists purely for interoperability with C code that was compiled with the -fshort-enums option 🫢. It makes GNU Fortran choose the smallest INTEGER kind a given enumerator set fits in, and hand all its enumerators that kind. Slay, but only if you need it.
  • -finline-arg-packing β€” okay so when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size thing, or as an argument to a procedure that doesn't have an explicit interface, that argument may have to be packed; that is, put into contiguous memory. Example time β€” 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 is done by inline code. This allows for more optimization while increasing code size πŸ“ˆ.

-finline-arg-packing is implied by any of the -O options except when optimizing for size via -Os. And if your 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. You can find instances of packing by using -Warray-temporaries πŸ”.

  • -fexternal-blas β€” this makes gfortran generate calls to BLAS functions for some matrix operations like MATMUL, instead of using our own algorithms, 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 has to be specified at link time, no cap.
  • *-fblas-matmul-limit=n* β€” only significant when -fexternal-blas is in effect. Matrix multiplication of matrices with size larger than (or equal to) n is performed by calls to BLAS functions, while others are 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-intrinsics
  • *-finline-intrinsics=intr1,intr2,...* β€” prefer generating inline code over calls to libgfortran functions to implement intrinsics πŸ’–.

Usage of intrinsics can be implemented either by generating a call to the libgfortran library function or by directly generating inline code. For most intrinsics, only a single variant is available, and there is no choice of implementation. However, some intrinsics can use a library function or inline code, where inline code typically offers opportunities for additional optimization over a library function ✨. With -finline-intrinsics=... or -fno-inline-intrinsics=..., the choice applies only to the intrinsics present in the comma-separated list provided as argument.

For each intrinsic, if no choice of implementation was made through either of the flag variants, a default behavior is chosen depending on optimization: library calls are generated when not optimizing or when optimizing for size; otherwise inline code is preferred.

The set of intrinsics allowed as argument to -finline-intrinsics= is currently limited to MAXLOC and MINLOC πŸ™ˆ. The effect of the flag is moreover limited to calls of those intrinsics without DIM argument and with ARRAY of a non-CHARACTER type. The case of rank-1 argument and DIM argument present, i.e. MAXLOC(A(:),DIM=1) or MINLOC(A(:),DIM=1) is inlined unconditionally for numeric rank-1 array argument A.

  • *-finline-matmul-limit=n* β€” when front-end optimization is active, some calls to the MATMUL intrinsic function are inlined πŸ”₯. This may result in code size increase if the size of the matrix cannot be determined at compile time, as code for both cases is 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 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 β€” allow indirect recursion by forcing all local arrays to be allocated on the stack. This flag cannot be used together with -fmax-stack-var-size= or -fno-automatic πŸ’€.
  • -finit-local-zero
  • -finit-derived
  • *-finit-integer=n*
  • *-finit-real=<zero|inf|-inf|nan|snan>*
  • *-finit-logical=<true|false>*
  • *-finit-character=n* β€” the -finit-local-zero option instructs 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 ✨. Finer-grained initialization options are provided by the -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real and imaginary parts of local COMPLEX variables), -finit-logical=<true|false>, and -finit-character=n (where n is an ASCII character value) options.

With -finit-derived, components of derived type variables are initialized according to these flags 🫢. Components whose type is not covered by an explicit -finit-* flag are treated as described above with -finit-local-zero.

These options do not initialize:

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

(These limitations may be removed in future releases).

Note that the -finit-real=nan option initializes REAL and COMPLEX variables with a quiet NaN. For a signalling NaN use -finit-real=snan; note, however, that compile-time optimizations may convert them into quiet NaN and that trapping needs to be enabled (e.g. via -ffpe-trap) ⚠️.

The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. 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.

Finally, note that enabling any of the -finit-* options silences warnings that would have been emitted by -Wuninitialized for the affected local variables. iykyk.

  • -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. 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. The same form of this option should be used for all files that share a COMMON block. To avoid potential alignment issues in COMMON blocks, it is recommended to order objects from largest to smallest.
  • -fno-protect-parens β€” by default the parentheses in expression are honored for all optimization levels such that the compiler does not do any reassociation. Using -fno-protect-parens allows the compiler to reorder REAL and COMPLEX expressions to produce faster code πŸ”₯. Note that for the reassociation 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 is either unallocated or has a different shape πŸ‘‘. The 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 is only a single call to f. 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. 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.

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

🌸 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 whole section bestie πŸ’€.


πŸ› BUGS πŸ›

For instructions on reporting bugs, see <https://bugzilla.redhat.com/>. 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.


πŸ‘‘ AUTHOR πŸ‘‘

See the Info entry for gfortran for contributors to GCC and GNU Fortran. Legends, every single one πŸ’–.

okay bestie, final section, and it's the legal one, so we're gonna be cute but also very precise, because lawyers are the only people more unhinged than a Makefile at 3am 🫢

Copyright (c) 2004-2025 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. πŸ“œβœ¨

fr fr, that's the whole permission grant, verbatim, no paraphrasing, no vibes-based reinterpretation. i am not editing legal text, i am simply delivering it with sparkle πŸ’…


🌸 the cover texts, in all their glory 🌸

(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.
bestie if you're out here copying and modifying this GNU Manual, please keep those cover texts intact, okay? it's giving "respect the drip" and it's literally a condition of the license πŸ™ˆ

and that's the page!! πŸŽ€ you just read an entire man page, which is genuinely iconic of you, no cap πŸ‘‘

so anyway, this whole thing came out of the gcc-15 release and it's dated 2026-07-22, and it lives in section 1 of the manual as GFORTRAN(1) β€” go forth, compile something unhinged, and remember: warnings are just the compiler trying to love you πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from
  • fedora 44: gcc15-gfortran 15.3.1-1.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND curl
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms