GFORTRAN(1)

๐Ÿ“ฆ
version 14.4.0 ยท 4 versions
, in ubuntu stonking

๐Ÿ’– hi bestie, this is gfortran ๐Ÿ’–

okay so you opened the manual page for gfortran, aka the GNU Fortran compiler, and yeah โ€” the header up top says GFORTRAN(1) and it lives in the GNU corner of your man pages. this thing is long, so grab a snack ๐Ÿ“, because I am going section by section and I am not skipping a single flag. no cap, not one.


๐Ÿซถ NAME ๐Ÿซถ

  • gfortran โ€” the GNU Fortran compiler. that's it, that's the whole identity. iconic. โœจ

๐Ÿ“œ SYNOPSIS ๐Ÿ“œ

gfortran [-c|-S|-E]
         [-g] [-pg] [-Olevel]
         [-Wwarn...] [-pedantic]
         [-Idir...] [-Ldir...]
         [-Dmacro[=defn]...] [-Umacro]
         [-foption...]
         [-mmachine-option...]
         [-o outfile] infile...
only the most useful options are listed up here โ€” the rest of them are further down. yes I'm telling you to keep scrolling. I'm not gatekeeping anything ๐Ÿ’…

๐Ÿ’ซ DESCRIPTION ๐Ÿ’ซ

okay so the tea:

  • the gfortran command supports all the options that the gcc command supports. this manual only documents the ones that are specific to GNU Fortran, because duh, the gcc man page already has the rest. ๐Ÿฆ‹
  • everything โ€” all GCC options and all GNU Fortran options โ€” is accepted by gfortran and by gcc (plus any other drivers that got built at the same time, like g++). why? because once GNU Fortran is part of the GCC distribution, all the relevant drivers start accepting GNU Fortran options. it's giving "we're all in this together" fr fr.
  • some options come in a positive form and a negative form โ€” the negative form of -ffoo would be -fno-foo. this manual documents only one of the two, whichever one is not the default. so if you don't see the twin, that's why. ๐Ÿ’€

โœจ OPTIONS โœจ

here's the full rundown of every option that's specific to GNU Fortran, sorted by category. the actual explanations live in the sections right after this. buckle up. ๐ŸŽ€

๐ŸŒธ 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

๐ŸŒˆ 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-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 what flavor of Fortran the compiler is willing to read. let's go one by one, bestie.

  • -ffree-form, -ffixed-form โ€” pick the layout your source file uses. free form is the Fortran 90 glow-up; fixed form is what all the older Fortran programs were rocking back in the day. if you don't pass either one, the compiler sniffs the file extension and decides for you. ๐ŸŽ€
  • -fall-intrinsics โ€” makes every intrinsic procedure get accepted, GNU-specific extensions included. super handy alongside -std= when you want to force standard-compliance but still flex the full range of intrinsics gfortran has. side effect bestie, listen: -Wintrinsics-std gets ignored, 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 out there calls external procedures with mismatches between the call and the procedure definition, or mismatches between different calls. that code is non-conforming and normally gets flagged as an error. this option downgrades that error to a warning, and the only way to silence it is turning off all warnings with -w. only a single occurrence per argument gets flagged. -fallow-argument-mismatch is implied by -std=legacy.
using this option is strongly discouraged. you can write standard-conforming code that accepts different argument types โ€” use an explicit interface and TYPE(*). do that instead. ๐Ÿ™ˆ
  • -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 down to 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 that start with d or D in fixed form sources. give it -fd-lines-as-code and those lines get treated as if the first column contained a blank. give it -fd-lines-as-comments and they're treated as comment lines. cute, right? ๐Ÿฆ‹
  • -fdec โ€” DEC compatibility mode. turns on extensions and features that mimic what older compilers (like DEC) did by default.
these features are non-standard and should be avoided at all costs, bestie. seriously. the full documentation has the details on how GNU Fortran implements them.

other flags this switch turns on: -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 character literals in assignments and DATA statements for variables that aren't characters. wild, but okay. ๐ŸŒธ
  • -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 โ€” use Fortran 90 derived types instead wherever you can. ๐Ÿ‘‘
  • -fdec-intrinsic-ints โ€” enables the B/I/J/K kind variants of existing integer functions (think BIAND, IIAND, JIAND, etc...). the full documentation has the complete list of intrinsics. ๐Ÿ”ฅ
  • -fdec-math โ€” obsolete flag alert. its whole purpose was enabling legacy math intrinsics like COTAN and degree-valued trig functions (e.g. TAND, ATAND, etc...) for compatibility with older code. this option is no longer operable. those trig functions are now either part of Fortran 2023 or GNU extensions. rest in peace, king ๐Ÿ’€
  • -fdec-static โ€” enables DEC-style STATIC and AUTOMATIC attributes so you can explicitly state where variables and other objects get stored. ๐ŸŽ€
  • -fdec-include โ€” enables parsing INCLUDE as a statement, in addition to parsing it as an INCLUDE line. when it's parsed as an INCLUDE statement, INCLUDE doesn't have to sit on a single line and can use line continuations. ๐ŸŒˆ
  • -fdec-format-defaults โ€” lets the format specifiers F, G and I be used without width specifiers; default widths get used instead. โœจ
  • -fdec-blank-format-item โ€” enables a blank format item at the end of a format specification, i.e. nothing following that final comma. ๐Ÿ™ˆ
  • -fdollar-ok โ€” allows $ as a valid non-first character in a symbol name. symbols that start with $ get rejected, because it's honestly unclear which rules to apply to implicit typing โ€” different vendors implement different rules. using $ in IMPLICIT statements is rejected too. ๐Ÿ’…
  • -fbackslash โ€” flips how backslashes inside string literals are read: instead of a single backslash character, you get "C-style" escape characters. these combinations expand โ€” \a, \b, \f, \n, \r, \t, \v, \\, and \0 โ€” into 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 (each n being 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. bestie, consider this the "do not perceive me" setting. ๐Ÿซถ
  • -ffixed-line-length-n โ€” sets the column after which characters get 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 continued character constants never get implicit spaces appended to fill out the line. -ffixed-line-length-0 means the exact same thing as -ffixed-line-length-none. ๐ŸŒธ


nope, we're not done, bestie โ€” keep going, there's so much more ๐Ÿ’–

  • -fno-pad-source โ€” ok so normally, fixed-form lines get spaces assumed after them (like they got padded out to that length) when the line is short ๐Ÿ’…. This padding does not happen if you use -ffixed-line-length-0, -ffixed-line-length-none, or this -fno-pad-source flag. And with any of those options, continued character constants never get implicit spaces tacked on to fill out the line either. no cap โœจ
  • -ffree-line-length-n โ€” sets the column after which characters are ignored in typical free-form lines in the source file. the default is 132 ๐ŸŽ€. n can be none, which means the whole line counts, every last character. and -ffree-line-length-0 means exactly the same thing as -ffree-line-length-none โ€” twins, fr fr ๐Ÿ‘ฏ
  • -fmax-identifier-length=n โ€” sets the max allowed identifier length, bestie. typical values are 31 (Fortran 95) and 63 (Fortran 2003 and later) ๐ŸŒธ
  • -fimplicit-none โ€” says no implicit typing allowed, unless an explicit IMPLICIT statement overrides it. lowkey it's the same as pasting implicit none at the start of every single procedure ๐Ÿ‘‘
  • -fcray-pointer โ€” turns on the Cray pointer extension, which hands you C-like pointer functionality. iconic behavior honestly โœจ
  • -fopenacc โ€” enables handling of OpenACC directives !$acc in free-form Fortran, plus !$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, so it's only supported on targets that actually have -pthread support ๐Ÿซถ. also, -fopenacc implies -frecursive.
  • -fopenmp โ€” enables handling of OpenMP directives !$omp in Fortran. it additionally enables the conditional compilation sentinel !$ in Fortran. in fixed source form Fortran, those 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, so โ€” same deal โ€” only supported on targets with -pthread support. and -fopenmp implies -fopenmp-simd and -frecursive ๐Ÿ’…
  • -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 โš ๏ธ. on top of that, all files that might deallocate or reallocate a variable that's been allocated with an OpenMP allocator also have to be compiled with this option. that includes intrinsic assignment to allocatable variables when reallocation may occur, and deallocation due to either of these: end of scope, explicit deallocation, intent(out), deallocation of allocatable components, etc. ๐Ÿ˜ญ

okay but the good news: files that don't change the allocation status โ€” or that only touch components of a derived type that haven't been allocated using those two directives โ€” do not need this option. and neither do files that handle such variables after they've been deallocated, or allocated by the normal Fortran allocator ๐ŸŒˆ

  • -fopenmp-simd โ€” enables handling of OpenMP's simd, declare simd, declare reduction, assume, ordered, scan and loop directives, plus combined or composite directives with simd as a constituent together with !$omp in Fortran โœจ. it also enables the conditional compilation sentinel !$ in Fortran, and in fixed source form Fortran those sentinels can start with c or * too. every other OpenMP directive gets ignored ๐Ÿ’€. and unless -fopenmp is additionally specified, the loop region binds to the current task region, independent of the specified bind clause.
  • -fno-range-check โ€” disables range checking on results of simplification of constant expressions during compilation ๐Ÿ™ˆ. for example, GNU Fortran will throw a compile-time error when simplifying a = 1. / 0. with this option, no error โ€” a just gets the value +Infinity. if an expression evaluates to something 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 ๐ŸŒธ
  • -fdefault-integer-8 โ€” sets the default integer and logical types to an 8 byte wide type. this option also affects the kind of integer constants like 42 ๐Ÿ”ข. unlike -finteger-4-integer-8, it does not promote variables with explicit kind declaration.
  • -fdefault-real-8 โ€” sets the default real type to an 8 byte wide type. this also affects the kind of non-double real constants like 1.0. and it promotes the default width of DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes if possible ๐Ÿ‘€. if -fdefault-double-8 is given along with fdefault-real-8, then DOUBLE PRECISION and double real constants are not promoted. unlike -freal-4-real-8, fdefault-real-8 does not promote variables with explicit kind declarations ๐Ÿ’…
  • -fdefault-real-10 โ€” sets the default real type to 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, DOUBLE PRECISION and double real constants are not promoted. unlike -freal-4-real-10, fdefault-real-10 does not promote variables with explicit kind declarations ๐ŸŽ€
  • -fdefault-real-16 โ€” sets the default real type to an 16 byte wide type. yeah, it also affects the kind of non-double real constants like 1.0. and yep, 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, DOUBLE PRECISION and double real constants are not promoted. unlike -freal-4-real-16, fdefault-real-16 does not promote variables with explicit kind declarations ๐Ÿ’œ
  • -fdefault-double-8 โ€” sets the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type. does nothing if that's already the default ๐Ÿซถ. this option stops -fdefault-real-8, -fdefault-real-10, and -fdefault-real-16 from promoting DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes. the bouncer of the double-precision club, basically ๐Ÿ›‘
  • -finteger-4-integer-8 โ€” promotes all INTEGER(KIND=4) entities to INTEGER(KIND=8) entities. if KIND=8 isn't available, an error gets issued ๐Ÿ˜ญ. this option should be used with care and may not be suitable for your codes, bestie. areas of possible concern include calls to external procedures, alignment in EQUIVALENCE and/or COMMON, generic interfaces, BOZ literal constant conversion, and I/O. inspecting the intermediate representation of the translated Fortran code โ€” produced by -fdump-tree-original โ€” is suggested ๐Ÿ‘€
  • -freal-4-real-8
  • -freal-4-real-10
  • -freal-4-real-16
  • -freal-8-real-4
  • -freal-8-real-10
  • -freal-8-real-16 โ€” promote all REAL(KIND=M) entities to REAL(KIND=N) entities. if REAL(KIND=N) isn't available, an error gets issued โš ๏ธ. the -freal-4- flags also affect the default real kind, and the -freal-8- flags also affect the double-precision real kind. all other real-kind types are unaffected by this option. the promotion also gets applied to real literal constants of default and double-precision kind, and to 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, plus calls to intrinsic procedures when passing a value to the kind= dummy argument. inspecting the intermediate representation of the translated Fortran code โ€” produced by -fdump-fortran-original or -fdump-tree-original โ€” is suggested ๐Ÿ’–
  • -std=std โ€” specifies the standard the program is expected to conform to, which can 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 the extensions GNU Fortran supports โ€” though you'll get warnings for obsolete extensions that aren't recommended for new code. the legacy value is equivalent but without those warnings for obsolete extensions, and it may be useful for old non-standard 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 get given for all extensions beyond the relevant language standard, and warnings get given for the Fortran 77 features that are permitted but obsolescent in later standards.

the deprecated option -std=f2008ts acts as an alias for -std=f2018. it's only there for backwards compatibility with earlier gfortran versions, and it should not be used any more ๐Ÿšซ

  • -ftest-forall-temp โ€” enhances test coverage by forcing most forall assignments to use temporary ๐Ÿงช

โœจ Enable and customize preprocessing โœจ

okay so, many Fortran compilers โ€” GNU Fortran included โ€” let you pass the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) so you can do conditional compilation ๐Ÿ’–. in the case of GNU Fortran, this is the GNU C Preprocessor in the traditional mode.

on systems with case-preserving file names, the preprocessor gets invoked automatically if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08 ๐Ÿค–.

to manually invoke the preprocessor on any file, use -cpp. to disable preprocessing on files where it runs automatically, use -nocpp ๐Ÿ›‘

If a preprocessed file pulls in another file with the Fortran INCLUDE statement, bestieโ€ฆ that included file does not get preprocessed. ๐Ÿ˜ญ Nope. If you want it preprocessed, use the equivalent preprocessor statement #include instead. slay.

When GNU Fortran invokes the preprocessor, __GFORTRAN__ gets defined. โœ”๏ธ And you can use the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to figure out which version of the compiler you're on. For the deets, see Top,,Overview,cpp,The C Preprocessor.

GNU Fortran also supports a whole bunch of INTEGER and REAL kind types on top of the ones the Fortran standard requires. ๐Ÿ’… Whether any given kind type exists is architecture dependent โ€” so don't come for me if it's not there. These pre-defined 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, obviously. But 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. If you've got files like that, you can use the program coco to preprocess them (<http://www.daniellnagle.com/coco.html>).

The following options control preprocessing of Fortran code:

  • -cpp, -nocpp โ€” Enable preprocessing. The preprocessor gets 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 runs in traditional mode. Any restrictions of the file-format apply to preprocessed output too โ€” especially the limits on line length โ€” 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 is your 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.

  • -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 will let the compiler know the current working directory at the time of preprocessing. When this option is enabled, the preprocessor will emit, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC will use this directory, when it's present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats. This option is implicitly enabled if debugging information is enabled, but 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 "=" will be 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 "=" will be 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 "=" will be 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 will be 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 will need to quote the option. With sh and csh, "-D'name(args...)=definition'" works. slay.

-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 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 ๐Ÿ’–

Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler will continue to process the program in an attempt to report further errors to aid in debugging, but will not produce any compiled output. so no binary, bestie. ๐Ÿซ 

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

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. ๐Ÿ‘‘
  • -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. But here's the tea: without it, some GNU extensions and traditional Fortran features get supported too. With it, a whole bunch of those get rejected. Slay, gatekeeping.

Some besties try to use -pedantic to check their programs for conformance and then find out it does not do quite what they want โ€” like, it catches some nonstandard practices, but not all of them. Improvements to GNU Fortran in this area are welcome, so if you wanna be the main character who fixes itโ€ฆ ๐Ÿ’…

Fr fr, use this one in conjunction with -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023.

  • -pedantic-errors โ€” literally -pedantic but it produces errors instead of warnings. no soft launch, just consequences ๐Ÿ˜ญ
  • -Wall โ€” turns on the commonly used warning options for usage we recommend avoiding and that we believe are easy to avoid. Currently that includes -Waliasing, -Wampersand, -Wconversion, -Wsurprising, -Wc-binding-type, -Wintrinsics-std, -Wtabs, -Wintrinsic-shadow, -Wline-truncation, -Wtarget-lifetime, -Winteger-division, -Wreal-q-constant, -Wunused and -Wundefined-do-loop. it's giving "the deluxe warning bundle" โœจ
  • -Waliasing โ€” warns about possible aliasing of dummy arguments. Specifically: it warns if the same actual argument is associated with a dummy argument with INTENT(IN) and a dummy argument with INTENT(OUT) in a call with an explicit interface. ๐Ÿ‘€

The following example will trigger the warning:

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

call bar(a,a)
  • -Wampersand โ€” warns about a missing ampersand in continued character constants. You get this warning 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. iykyk ๐Ÿซ 
  • -Warray-temporaries โ€” warns about array temporaries generated by the compiler. The info from this warning is sometimes useful in optimization, so you can avoid such temporaries. optimization besties, this one's for you
  • -Wc-binding-type โ€” warns if the a variable might not be C interoperable. In particular, it warns if the variable was 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. ๐Ÿ”ฅ
  • -Wcharacter-truncation โ€” warns when a character assignment will truncate the assigned string. bye bye characters ๐Ÿ’€
  • -Wline-truncation โ€” warns when a source code line will be truncated. This option is implied by -Wall. For free-form source code, the default is -Werror=line-truncation, so truncations get reported as an error. periodt.
  • -Wconversion โ€” warns about implicit conversions that are likely to change the value of the expression after conversion. Implied by -Wall.
  • -Wconversion-extra โ€” warns about implicit conversions between different types and kinds. This option does not imply -Wconversion.
  • -Wextra โ€” enables some warning options for usages of language features which may be problematic. Currently that includes -Wcompare-reals, -Wunused-parameter and -Wdo-subscript. the extra sprinkle ๐ŸŽ€
  • -Wfrontend-loop-interchange โ€” warns when using -ffrontend-loop-interchange for performing loop interchanges.
  • -Wimplicit-interface โ€” warns if a procedure is called without an explicit interface. Note: this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units. ngl that's a big "trust me bro" ๐Ÿ˜ญ
  • -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. For example, 3/5 evaluates to 0. math girlies stay strong ๐Ÿ“
  • -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 an "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. iconic escape hatch โœจ
  • -Wno-overwrite-recursive โ€” do not warn when -fno-automatic is used with -frecursive. Recursion will be 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. ๐Ÿ’…
  • -Wreal-q-constant โ€” produces a warning if a real-literal-constant contains a "q" exponent-letter. not the q ๐Ÿ’€
  • -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 SELECT construct has a CASE that can never be matched as 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, -std=f2023 and -Wall. tab girlies, we see you ๐Ÿ™ˆ
  • -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.
  • -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 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 drama ๐Ÿ‘‘
  • -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 it just lets everything inโ€ฆ ๐Ÿ˜ญ
  • -Wunused-dummy-argument โ€” warns about unused dummy arguments. This option is implied by -Wall.
  • -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. yes bestie, the flag names are lowkey a trap ๐Ÿชค
  • -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. This option is implied by -Wextra. she's gone, and she was impure ๐Ÿ’€
  • -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 will optimize reallocation checks away. For instance, when the right-hand side contains the same variable multiplied by a scalar. See also -frealloc-lhs. hot loops besties, this is your glow-up tip โœจ
  • -Wrealloc-lhs-all โ€” warns when the compiler inserts code to for allocation or reallocation of an allocatable variable; this includes scalars and derived types. all of them. every single one. ๐Ÿซถ
  • -Wcompare-reals โ€” warns when comparing real or complex types for equality or inequality. This option is implied by -Wextra. comparing floats for equality is giving chaos ๐ŸŒˆ
  • -Wtarget-lifetime โ€” warns if the pointer in a pointer assignment might be longer than the its target. This option is implied by -Wall.
  • -Wzerotrip โ€” warns if a "DO" loop is known to execute zero times at compile time. This option is 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 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.

  • -Werror โ€” turns all warnings into errors. yes, all of them. no warnings survive ๐Ÿ™…

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


๐Ÿ›โœจ Options for debugging your program โœจ๐Ÿ›

GNU Fortran has various special options that are used for debugging your program. detective mode: activated ๐Ÿ•ต๏ธโ€โ™€๏ธ๐Ÿ’œ

  • -fdebug-aux-vars โ€” renames internal variables created by the gfortran front end and makes them accessible to a debugger. The name of the internal variables then 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". peak compiler-innards access, no cap ๐Ÿ’–
  • -ffpe-trap=list โ€” okay so this one is literally a bouncer for floating point exceptions ๐Ÿ’…. You hand it a list of 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 comma-separated list (it can be empty, no judgement) of either none โ€” which clears the whole set of exceptions being trapped โ€” or any of these icons โœจ:
    • invalid โ€” invalid floating point operation, such as SQRT(-1.0)
    • zero โ€” division by zero
    • overflow โ€” overflow in a floating point operation
    • underflow โ€” underflow in a floating point operation
    • inexact โ€” loss of precision during operation
    • denormal โ€” operation performed on a denormal value

The first five correspond to the five IEEE 754 exceptions, 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 โ€” 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. fr fr ๐Ÿซถ

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

Heads up bestie: once enabled, an exception cannot be disabled. There's no negative form, periodt. The only way out is clearing all traps by specifying none.

Many, if not most, floating point operations incur loss of precision due to rounding, and hence -ffpe-trap=inexact is likely to be uninteresting in practice. Like, snooze ๐Ÿฅฑ.

By default, no exception traps are enabled.

  • -ffpe-summary=list โ€” this one picks which floating-point exceptions get their flag status printed to ERROR_UNIT when you invoke STOP and ERROR STOP. list can be none, all, or a comma-separated list of: invalid, zero, overflow, underflow, inexact and denormal. (Scroll up to -ffpe-trap for a description of what each of those exceptions actually means ๐Ÿ’–.)

If the option is used more than once on the command line, only the last one is used. No merging, no stacking, just vibes.

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 that backtrace generation. Not me turning off the receipts tho ๐Ÿ™ˆ. 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 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 ๐Ÿ‘‘.

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 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 are 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 literally meaningless if the compiler is not doing a link step, so don't come for them ๐Ÿซถ.

  • -static-libgfortran โ€” on systems that provide libgfortran as 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 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. Legal girlies stay winning ๐Ÿ“œโœจ

๐ŸŒˆ 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 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(KINDw=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. Nostalgia is expensive bestie ๐Ÿ˜ญ
  • -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. Niche queen behaviour ๐Ÿ’…
  • -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. These are the "peek behind the curtain" options, iykyk ๐ŸŽ€

  • -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 which have only recently been added. Chaos, but make it compiler-flavoured ๐Ÿ’€
  • -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 which 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 which 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 which have only recently been added.
This option is deprecated; use -fdump-fortran-original instead. She's old news, retire her ๐Ÿ™ˆ
  • -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 which is not the default. You can figure out the other form by either removing no- or adding it. Math girlies thrive here ๐ŸŒธ

  • -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. Silently. Ignored. The disrespect ๐Ÿ˜ญ

  • -ff2c โ€” generate code designed to be compatible with code generated by g77 and f2c.

so likeโ€ฆ g77's calling conventions (originally implemented over in f2c โ€” vintage ๐Ÿ’€) say that functions returning type default REAL have to actually return the C type double, and functions returning type COMPLEX have to hand their values back through an extra argument in the calling sequence that points to where the return value should get stored. Under the default GNU calling conventions though? Nah, those functions just return their results exactly like they would in GNU C โ€” so default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. Also, this option implies -fsecond-underscore, unless -fno-second-underscore is explicitly requested. Periodt.

This does not affect the generation of code that interfaces with the libgfortran library. Don't worry about her ๐Ÿซถ

Caution: bestie, do not mix Fortran code compiled with -ff2c together with code compiled with the default -fno-f2c calling conventions. Calling COMPLEX or default REAL functions between program parts compiled with different calling conventions will break at execution time. Like, break break. ๐Ÿ˜ญ
Caution: this will also break code which 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 many UNIX Fortran compilers. It's giving legacy โœจ

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're out here experimenting with issues like integration of GNU Fortran into existing system environments (vis-ร -vis existing libraries, tools, and so on). Basically don't do it unless you know what you're doing ๐Ÿ’…

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, that 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. Iconic for debugging tbh ๐Ÿ‘‘

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. So the linker will not snitch. ๐Ÿ™ˆ

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. The worst kind of bug fr fr ๐Ÿ’€

In future versions of GNU Fortran we hope to improve naming and linking issues so that debugging always involves using the names as they appear in the source, even if the names as seen by the linker are mangled to prevent accidental linking between procedures with incompatible interfaces.

  • -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 external names with no underscores. GNU Fortran also appends two underscores to internal names with underscores to avoid naming collisions with external names.

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

Otherwise, with this option, 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.

  • -fcoarray=<keyword> โ€” the coarray situation, keyword by keyword:
    • none โ€” disable coarray support; using coarray declarations and image-control statements will produce 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 needs to be linked.
  • -fcheck=<keyword> โ€” turns on 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. (Yes, you can vibe-check your vibe-checks โœจ)
    • 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. Don't touch the loop counter bestie ๐Ÿšซ
  • mem โ€” enable generation of run-time checks for memory allocation.
Note: this option does not affect explicit allocations using the ALLOCATE statement, which will be 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 which are not marked as recursive. See also -frecursive.
Note: this check does not work for OpenMP programs and is disabled if used together with -frecursive and -fopenmp.

Example: assuming you have a file foo.f90, the command

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

will compile the file with all checks enabled as specified above except warnings for generated array temporaries. Slay ๐ŸŒธ

  • -fbounds-check โ€” deprecated alias for -fcheck=bounds. (Old โœจ, use the new one.)
  • -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. (the cross-reference got cut off in the source, bestie, not my fault ๐Ÿ’€) 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 the equivalent -ftail-call-workaround, it's disabled only in gfortran procedures with character arguments that call implicitly prototyped procedures.

Using this option can lead to problems including crashes due to insufficient stack space.

It is very strongly recommended to fix the code in question. The -fc-prototypes-external option can be used to generate prototypes which 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. So likeโ€ฆ don't get attached ๐Ÿฅ€

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

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

  • -fcheck-array-temporaries โ€” deprecated alias for -fcheck=array-temps.
  • -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. Do not say we didn't warn you ๐Ÿ’…

The default value for n is 65535.

  • -fmax-stack-var-size=n โ€” this option specifies the size in bytes of the largest array that will be 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 which 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. She's a work in progress ๐ŸŒˆ

The default value for n is 65536.

  • -fstack-arrays โ€” adding this option will make 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 will 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. Stack go brrr ๐Ÿ”ฅ

okay bestie, the OPTIONS party is STILL going and these next ones are giving extremely specific energy ๐ŸŽ€ let's get into it.

  • -fpack-derived โ€” this one tells GNU Fortran to pack derived type members as closely together as physically possible ๐Ÿงณ. Heads up though: code compiled with this option is likely to be incompatible with code compiled without it, and it may also run slower ๐Ÿ˜ญ.
  • -frepack-arrays โ€” in some circumstances GNU Fortran may pass assumed shape array sections via a descriptor describing a noncontiguous area of memory ๐ŸŒŠ. This option adds code to the function prologue to repack the data into a contiguous block at runtime.

This should result in faster accesses to the array โœจ. But it can introduce significant overhead to the function call, especially when the passed data is noncontiguous ๐Ÿ˜ฌ.

  • -fshort-enums โ€” provided for interoperability with C code that was compiled with the -fshort-enums option ๐Ÿซถ. It makes GNU Fortran choose the smallest INTEGER kind a given enumerator set will fit in, and gives all its enumerators that kind.
  • -finline-arg-packing โ€” when passing an assumed-shape argument of a procedure as actual argument to an assumed-size or explicit size, or as argument to a procedure that does not have an explicit interface, the argument may have to be packed, i.e. put into contiguous memory ๐Ÿง . Like this call to foo:
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, this packing will be performed 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 ๐Ÿ‘€. If the code contains a very large number of arguments that have to be packed, code size and also compilation time may become excessive ๐Ÿ˜ต. If that's the case, it may be better to disable this option. Instances of packing can be found by using -Warray-temporaries.

  • -fexternal-blas โ€” this one makes gfortran generate calls to BLAS functions for some matrix operations like MATMUL, instead of using its 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 will have to be specified at link time ๐Ÿ”—.
  • -fblas-matmul-limit=n โ€” only significant when -fexternal-blas is in effect. Matrix multiplication of matrices with size larger than (or equal to) n will be performed by calls to BLAS functions, while others will be handled by gfortran internal algorithms ๐Ÿงฎ. If the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices ๐Ÿ“.

The default value for n is 30.

  • -finline-matmul-limit=n โ€” when front-end optimization is active, some calls to the MATMUL intrinsic function will be 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 will disable inlining in all cases. Setting this option with a value of n will produce inline code for matrices with size up to n. If the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices ๐Ÿ“.

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

  • -frecursive โ€” 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 will be initialized according to these flags ๐ŸŒˆ. Components whose type is not covered by an explicit -finit-* flag will be 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 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 ๐Ÿ˜ตโ€๐Ÿ’ซ.

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

  • -falign-commons โ€” by default, gfortran enforces proper alignment of all variables in a COMMON block by padding them as needed ๐Ÿงฑ. On 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 expressions are honored for all optimization levels such that the compiler does not do any re-association ๐Ÿ›ก๏ธ. Using -fno-protect-parens allows the compiler to reorder REAL and COMPLEX expressions to produce faster code ๐ŸŽ๏ธ. Note that for the re-association optimization -fno-signed-zeros and -fno-trapping-math need to be in effect. The parentheses protection is enabled by default, unless -Ofast is given.
  • -frealloc-lhs โ€” an allocatable left-hand side of an intrinsic assignment is automatically (re)allocated if it 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 will only be 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 ๐Ÿ™…โ€โ™€๏ธ.


๐Ÿ› BUGS ๐Ÿ›

For instructions on reporting bugs, see <file:///usr/share/doc/gcc-14/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 ๐ŸŒˆ.


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

See the Info entry for gfortran for contributors to GCC and GNU Fortran ๐Ÿ’–.


Copyright (c) 2004-2024 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.

aaaand that's a wrap bestie ๐Ÿ’…๐Ÿ’– this whole page is from the gcc-14 set, dated 2026-09-02, and it's literally GFORTRAN(1) ๐Ÿฆ‹ slay, go forth and compile โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from