GFORTRAN(1)
π The GNU gfortran Manual Page π
Bestie, this is the GNU manual for the Fortran compiler, so everything here is straight from the source π
β¨ NAME β¨
gfortran is the GNU Fortran compiler π that's the whole name, no cap.
β¨ 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 top, so scroll down for the rest π
β¨ DESCRIPTION β¨
Okay so the gfortran command supports every option that gcc supports π¦ This page only covers the options that are specific to GNU Fortran.
All GCC and GNU Fortran options work with both gfortran and gcc, plus any other drivers built at the same time, like g++. Adding GNU Fortran to the GCC distribution is what lets all the relevant drivers accept Fortran options, which is so iconic π
Some options come in positive and negative versions. The negative form of -ffoo is -fno-foo. This manual only documents whichever form is not the default, so keep that in mind π§
β¨ OPTIONS β¨
Here's the summary of every option that's specific to GNU Fortran, sorted into groups. The explanations come right after π
π 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 -Wno-deprecated-openmp
-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
π Link Options
-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 -fexternal-blas64 -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
The following options control the details of the Fortran dialect the compiler accepts, so this is where the vibe gets specific β¨
-ffree-form,-ffixed-formβ These pick the layout used by the source file. Free form came in with Fortran 90, while fixed form was the traditional layout in older Fortran programs. If you don't specify either one, the source form gets decided by the file extension π-fall-intrinsicsβ This makes every intrinsic procedure get accepted, including the GNU-specific extensions π¦ It's useful alongside-std=if you want to force standard compliance but still get the full range of intrinsics gfortran has. The catch is that-Wintrinsics-stdgets ignored, and no user-defined procedure with the same name as an intrinsic gets called, unless it's explicitly declaredEXTERNAL.-fallow-argument-mismatchβ Some code calls external procedures with mismatches, either between the call and the procedure definition or between different calls. That code is nonconforming and usually throws an error. This option downgrades the error to a warning, and that warning can only be turned off by disabling all warnings with-w. Only one occurrence per argument gets flagged. This option is implied by-std=legacy.
Using this option is strongly discouraged π You can write standard-conforming code that allows different argument types by using an explicit interface and TYPE(*).
-fallow-invalid-bozβ A BOZ literal constant can only show up in a few contexts in standard-conforming Fortran. This option turns that error into a warning and lets a BOZ literal appear where the Fortran standard would normally ban it π-fd-lines-as-code,-fd-lines-as-commentsβ These give special treatment to lines starting withdorDin fixed form sources. With-fd-lines-as-code, they're treated as if the first column had a blank in it. With-fd-lines-as-comments, they're treated as comment lines.-fdecβ This turns on DEC compatibility mode, which enables extensions and other features that copy the default behavior of older compilers like DEC. These features are nonstandard, so they should be avoided at all costs π Check the full documentation for the details on how GNU Fortran implements them. Other flags this switch turns on are-fdollar-ok,-fcray-pointer,-fdec-char-conversions,-fdec-structure,-fdec-intrinsic-ints,-fdec-static,-fdec-math,-fdec-include,-fdec-blank-format-item, and-fdec-format-defaults. If-fd-lines-as-codeor-fd-lines-as-commentsare unset, then-fdecalso sets-fd-lines-as-comments.-fdec-char-conversionsβ This lets you use character literals in assignments andDATAstatements for non-character variables β¨-fdec-structureβ This enables DECSTRUCTUREandRECORD, plusUNION,MAP, and the dot (.) as a member separator, on top of%. It's only here for compatibility, so use Fortran 90 derived types instead whenever you can π-fdec-intrinsic-intsβ This enables the B/I/J/K kind variants of existing integer functions, likeBIAND,IIAND,JIAND, and so on. For a complete list of intrinsics, see Intrinsic Procedures.-fdec-mathβ This one is obsolete π₯ It used to enable legacy math intrinsics likeCOTANand the degree-valued trig functions (likeTAND,ATAND, and so on) so older code would still work. It doesn't work anymore, because those trig functions are now either part of Fortran 2023 or GNU extensions.-fdec-staticβ This enables DEC-styleSTATICandAUTOMATICattributes, so you can explicitly say how variables and other objects are stored π§-fdec-includeβ This letsINCLUDEbe parsed as a statement, in addition to being parsed as anINCLUDEline. When it's parsed as a statement,INCLUDEdoesn't have to sit on a single line and can use line continuations.-fdec-format-defaultsβ This lets the format specifiersF,G, andIbe used without width specifiers. Default widths get used instead πΈ-fdec-blank-format-itemβ This enables a blank format item at the end of a format specification, meaning there's nothing after the final comma π-fdollar-okβ This allows$as a valid non-first character in a symbol name. Symbols that start with$get rejected, since it's unclear which implicit typing rules to apply (different vendors do different things). Using$inIMPLICITstatements is also rejected.-fbackslashβ This changes how backslashes in string literals are read, from a single backslash character to "C-style" escape characters π These get expanded:\a,\b,\f,\n,\r,\t,\v,\\, and\0become the ASCII alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL characters, in that order. On top of that,\xnn,\unnnn, and\Unnnnnnnn(where eachnis a hexadecimal digit) get translated into the Unicode characters for those code points. Every other backslash-plus-character combo stays unexpanded.-fmodule-privateβ This sets the default accessibility of module entities toPRIVATE. Use-associated entities can't be accessed unless they're explicitly declaredPUBLICπ-ffixed-line-length-nβ This sets the column after which characters get ignored in typical fixed-form source lines. Unless-fno-pad-sourceis used, it also sets the column that spaces are assumed through after the ends of short fixed-form lines, as if the line were padded to that length. Popular values fornare72(the standard and the default),80(card image), and132(matching the "extended-source" options in some popular compilers).ncan also benone, which means the entire line is meaningful and continued character constants never get implicit spaces appended to fill out the line.-ffixed-line-length-0does the exact same thing as-ffixed-line-length-noneπ-fno-pad-sourceβ okay so by default, fixed-form lines get spaces assumed after the end of short lines, like they're padded out to full length π That doesn't happen if-ffixed-line-length-0,-ffixed-line-length-none, or-fno-pad-sourceis used. With any of those, continued character constants never get implicit spaces tacked on to fill the line π-ffree-line-length-nβ this sets the column after which characters get ignored in typical free-form lines π¦ The default is132.ncan benone, which means the entire line is meaningful. And-ffree-line-length-0is the same thing as-ffree-line-length-noneβ¨-fmax-identifier-length=nβ lets you set the maximum allowed identifier length π§ Typical values are31(Fortran 95) and63(Fortran 2003 and later).-fimplicit-noneβ no implicit typing allowed, unless you override it with explicitIMPLICITstatements π ββοΈ It's the same as puttingimplicit noneat the start of every procedure, so it's giving strict π-fcray-pointerβ turns on the Cray pointer extension, which gives you C-like pointer functionality πΈ-fopenaccβ enables handling of OpenACC directives!$accin free-form Fortran, plus!$acc,c$acc, and*$accin fixed-form Fortran π₯ With this on, the compiler generates accelerated code according to the OpenACC Application Programming Interface v2.6, which lives athttps://www.openacc.org. It implies-pthread, so it's only supported on targets that support-pthread. It also implies-frecursiveβ¨-fopenmpβ enables handling of OpenMP directives!$ompin Fortran, and also turns on the conditional compilation sentinel!$π In fixed-source-form Fortran, the sentinels can also start withcor*. With this on, the compiler generates parallel code according to the OpenMP Application Program Interface v4.5, found athttps://www.openmp.org. It implies-pthread, so it's only supported on targets that have-pthreadsupport. It also implies-fopenmp-simdand-frecursiveπ-fopenmp-allocatorsβ enables handling of allocation, reallocation, and deallocation of Fortran allocatable and pointer variables that get allocated with the!$omp allocatorsand!$omp allocateconstructs π«Ά Files containing either directive have to be compiled with this option in addition to-fopenmp. Also, every file that might deallocate or reallocate a variable allocated with an OpenMP allocator has to be compiled with this option too. That includes intrinsic assignment to allocatable variables when reallocation may happen, and deallocation from end of scope, explicit deallocation,intent(out), deallocation of allocatable components, etc. Files that don't change the allocation status, or only touch components of a derived type that weren't allocated with those two directives, don't need it. Same goes for files that handle these variables after they've been deallocated, or allocated by the normal Fortran allocator π-fopenmp-simdβ enables handling of OpenMP'ssimd,declare simd,declare reduction,assume,ordered,scan, andloopdirectives, plus combined or composite directives withsimdas a constituent, all written with!$ompin Fortran π¦ It also enables the conditional compilation sentinel!$, and in fixed-source-form Fortran the sentinels can start withcor*. Other OpenMP directives get ignored. Unless-fopenmpis also specified, theloopregion binds to the current task region, no matter whatbindclause you gave it π-fno-range-checkβ disables range checking on the results of simplifying constant expressions during compilation π For example, GNU Fortran errors at compile time when simplifyinga = 1. / 0. With this option, no error shows up andagets the value+Infinity. If an expression lands outside the relevant range of["-HUGE()":HUGE()], it gets replaced with-Infor+Inf, whichever fits. Similarly,DATA i/Z'FFFFFFFF'/causes an integer overflow on most systems, but with-fno-range-checkthe value wraps around andigets initialized to-1instead π-fdefault-integer-8β sets the default integer and logical types to an 8-byte-wide type π This also affects the kind of integer constants like42. Unlike-finteger-4-integer-8, it does not promote variables with an 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 like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-8, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations π-fdefault-real-10β sets the default real type to a 10-byte-wide type π§ This also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-10,fdefault-real-10does not promote variables with explicit kind declarations π«§-fdefault-real-16β sets the default real type to a 16-byte-wide type π This also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations π-fdefault-double-8β sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8-byte-wide type π If that's already the default, it does nothing. This option stops-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes π-finteger-4-integer-8β promotes allINTEGER(KIND=4)entities toINTEGER(KIND=8)entities π¨ IfKIND=8isn't available, you get an error. Use this one with care, because it might not suit your code. Things to watch out for include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, 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β these promote allREAL(KIND=M)entities toREAL(KIND=N)entities π IfREAL(KIND=N)isn't available, you get an error. The-freal-4-flags also affect the default real kind, and the-freal-8-flags affect the double-precision real kind. All other real-kind types are unaffected. The promotion also applies to real literal constants of default and double-precision kind, with a specified kind number of 4 or 8 respectively. However,-fdefault-real-8,-fdefault-real-10,-fdefault-real-10, and-fdefault-double-8take precedence for the default and double-precision real kinds, both for real literal constants and for declarations without a kind number. Heads up: forREAL(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 might not suit your code. Areas of concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, I/O, and calls to intrinsic procedures when passing a value to thekind=dummy argument. Inspecting the intermediate representation of the translated Fortran code, produced by-fdump-fortran-originalor-fdump-tree-original, is suggested π
NOTE: These options are incompatible with user defined derived type I/O (DTIO). Not the vibe π
-std=stdβ sets the standard your program is expected to conform to π It can be one off95,f2003,f2008,f2018,f2023,gnu, orlegacy. The default isgnu, which is a superset of the latest Fortran standard that includes every extension GNU Fortran supports, although you'll get warnings for obsolete extensions that aren't recommended for new code.legacyis equivalent but without those obsolete-extension warnings, so it's handy for old nonstandard programs π§ Thef95,f2003,f2008,f2018, andf2023values mean strict conformance to Fortran 95, Fortran 2003, Fortran 2008, Fortran 2018, and Fortran 2023 respectively. You'll get errors for any extension beyond the relevant language standard, and warnings for Fortran 77 features that are allowed but obsolescent in later standards π« The deprecated-std=f2008tsacts as an alias for-std=f2018. It's only there for backwards compatibility with earlier gfortran versions and shouldn't be used anymore π₯-std=f202yacts as an alias for-std=f2023and turns on proposed features for testing Fortran 202y. As the Fortran 202y standard develops, the implementation might change or the experimental new features might get removed π§ͺ-ftest-forall-tempβ boosts test coverage by forcing mostforallassignments to use a temporary π§ͺ-funsignedβ allows the experimental unsigned extension π§ͺβ¨
β¨ Enable and customize preprocessing β¨
okay bestie, so a bunch of Fortran compilers (GNU Fortran included π
) let you run your source through a C preprocessor (CPP, sometimes also called the Fortran preprocessor, FPP) so you can do conditional compilation π¦. For GNU Fortran that's the GNU C Preprocessor in traditional mode. On systems with case-preserving file names, it gets auto-invoked if your filename ends in .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. Want to run it on any file manually? Use -cpp. Want to stop it running on files where it would've kicked in automatically? Use -nocpp π
When you're compiling a preprocessed file, use -fpreprocessed β¨ this skips the C preprocessor.
If a preprocessed file pulls in another file with the Fortran INCLUDE statement, that included file is not preprocessed π to preprocess included files, use the equivalent preprocessor statement #include instead.
If GNU Fortran invokes the preprocessor, __GFORTRAN__ gets defined πΈ and the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ can be used to figure out the version of the compiler. See Top,,Overview,cpp,The C Preprocessor for details.
GNU Fortran also supports a bunch of INTEGER and REAL kind types on top of the ones the Fortran standard requires π which kinds you actually get is architecture dependent. These predefined macros let you conditionally include code for the extra kinds: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__.
CPP is the de facto standard for preprocessing Fortran code, but Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) also defines Conditional Compilation. It's not widely used, and GNU Fortran doesn't directly support it ngl π₯²
The following options control preprocessing of Fortran code:
-cpp,-nocppβ Turns preprocessing on. The preprocessor is automatically invoked if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08, but use-cppto manually enable it for any kind of Fortran file. To disable preprocessing of files with any of those extensions, use the negative form:-nocpp. The preprocessor runs in traditional mode, and any file format restrictions (especially the limits on line length) apply to preprocessed output as well, so it might be advisable to use the-ffree-line-length-noneor-ffixed-line-length-noneoptions π-dMβ Instead of the normal output, you get a list of#definedirectives for all the macros defined during the preprocessor run, predefined ones included π§ this is how you find out what's predefined in your version of the preprocessor. Assuming you have no filefoo.f90, the command:
touch foo.f90; gfortran -cpp -E -dM foo.f90
shows all the predefined macros.
-dDβ Like-dM, except it does not include the predefined macros, and it outputs both the#definedirectives and the result of preprocessing. Both kinds of output go to the standard output file.-dNβ Like-dD, but only emits the macro names, not their expansions.-dUβ LikedDexcept only macros that get expanded, or whose definedness gets tested in preprocessor directives, are output π the output is delayed until the use or test of the macro, and#undefdirectives are also output for macros that were tested but undefined at that time.-dIβ Outputs#includedirectives in addition to the result of preprocessing.-fworking-directoryβ Enables linemarkers in the preprocessor output that tell the compiler what the current working directory was at preprocessing time. With this on, the preprocessor emits, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC uses that directory (when it's in the preprocessed input) as the current working directory in some debugging information formats. This is implicitly enabled if debugging information is enabled, but you can inhibit it with the negated form-fno-working-directory. If the-Pflag is on the command line, this option has no effect, since no#linedirectives get emitted whatsoever π ββοΈ-idirafter dirβ Searchesdirfor include files, but does it after all the directories specified with-Iand the standard system directories have been exhausted.diris treated as a system include directory. Ifdirbegins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-imultilib dirβ Usesdiras a subdirectory of the directory containing target-specific C++ headers.-iprefix prefixβ Specifiesprefixas the prefix for subsequent-iwithprefixoptions. If the prefix represents a directory, you should include the final/π-isysroot dirβ This one's like the--sysrootoption, but it only applies to header files. See the--sysrootoption for more information.-iquote dirβ Searchesdironly for header files requested with#include "file". They are not searched for#include <file>, and this happens before all the directories specified by-Iand before the standard system directories. Ifdirbegins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-isystem dirβ Searchesdirfor header files, after all the directories specified by-Ibut before the standard system directories. It gets marked as a system directory, so it gets the same special treatment as the standard system directories. Ifdirbegins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-nostdincβ Doesn't search the standard system directories for header files. Only the directories you specified with-Ioptions (and the directory of the current file, if appropriate) get searched π«-undefβ Doesn't predefine any system-specific or GCC-specific macros. The standard predefined macros stay defined.-Apredicate=answerβ Makes an assertion with the predicatepredicateand the answeranswer. This form is preferred over the older form-A predicate(answer), which is still supported, because it doesn't use shell special characters π-A-predicate=answerβ Cancels an assertion with the predicatepredicateand the answeranswer.-Cβ Doesn't discard comments. All comments get passed through to the output file, except for comments in processed directives, which get deleted along with the directive.
You should be prepared for side effects when using -C, because it makes the preprocessor treat comments as tokens in their own right π« for example, comments at the start of what would be a directive line turn that line into an ordinary source line, since the first token on the line is no longer a #.
Warning: this currently handles C-style comments only. The preprocessor does not yet recognize Fortran-style comments.
-CCβ Doesn't discard comments, including during macro expansion. It's like-C, except comments contained within macros also get passed through to the output file where the macro is expanded.
On top of the side effects of -C, the -CC option converts all C++-style comments inside a macro into C-style comments. This stops later uses of that macro from accidentally commenting out the rest of the source line π§Ό -CC is generally used to support lint comments.
Warning: this currently handles C- and C++-style comments only. The preprocessor does not yet recognize Fortran-style comments.
-Dnameβ Predefinesnameas a macro, with definition1.-Dname=definitionβ The contents ofdefinitionare tokenized and processed as if they appeared during translation phase three in a#definedirective. The definition gets truncated by embedded newline characters.
If you're invoking the preprocessor from a shell (or shell-like program), you may need the shell's quoting syntax to protect characters like spaces that mean something in shell syntax π
If you want to define a function-like macro on the command line, write its argument list in surrounding parentheses before the equals sign (if any). Parentheses mean something 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're given on the command line. All -imacros file and -include file options get processed after all the -D and -U options.
-Hβ Prints the name of each header file used, along with the other normal activities. Each name is indented to show how deep it is in the#includestack π-Pβ Inhibits generation of linemarkers in the preprocessor output. This might be useful when running the preprocessor on something that isn't C code and is sent to a program that might get confused by the linemarkers.-Unameβ Cancels any previous definition ofname, whether it was built in or provided with a-Doption.
β¨ Options to request or suppress errors and warnings β¨
okay so errors are diagnostic messages that say the GNU Fortran compiler can't compile that piece of source code π the compiler keeps going anyway to report more errors and help you debug, but it doesn't produce any compiled output.
Warnings are diagnostic messages about constructions that aren't inherently wrong, but are risky or suggest there's probably a bug in your program π unless -Werror is specified, they don't stop your program from compiling.
You can request lots of specific warnings with options that begin with -W. For example, -Wimplicit requests warnings on implicit declarations. Each of these specific warning options also has a negative form starting with -Wno- that turns the warning off, like -Wno-implicit. This manual only lists one of the two forms, whichever one isn't the default π§
These options control the amount and kinds of errors and warnings GNU Fortran produces:
-fmax-errors=nβ Limits the maximum number of error messages ton. Once you hit that, GNU Fortran bails out instead of trying to keep processing the source code π ifnis0, there's no limit on the number of error messages produced.-fsyntax-onlyβ bestie, this one just checks your code for syntax errors π and does not actually compile it π . The only thing it makes is module files for each module in the code β¨, and no other output file at all.-Wpedantic,-pedanticβ these throw warnings at you for using Fortran extensions π .-pedanticalso goes after C-language stuff when it shows up in GNU Fortran source files, like using\ein a character constant inside a directive like"#include"π. Valid Fortran programs compile fine with or without it π«Ά, but without it, GNU's extra goodies and traditional Fortran features still work. With it on, a lot of them get rejected π«.
Some people use -pedantic as a conformance checker π§ and then realise it doesn't quite do what they want. It catches some nonstandard stuff, but not all of it π. Improvements in this area are very welcome π.
Use this together with -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023 π.
-pedantic-errorsβ same energy as-pedantic, except you get errors instead of warnings π¨.-Wallβ turns on the commonly used warnings for stuff we recommend avoiding, and that we think is easy to avoid π§Ή. Right now that's-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loopπ.-Waliasingβ warns about possible aliasing of dummy arguments π―. Specifically, it warns if the same actual argument gets associated with a dummy argument withINTENT(IN)and a dummy argument withINTENT(OUT)in a call with an explicit interface π«£. Here's an example that triggers it:
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 π. This warning is given with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-std=f2023. Heads up π¨: with no ampersand in a continued character constant, GNU Fortran assumes the continuation happens at the first non-comment, non-whitespace character after the ampersand that started the continuation π§.-Warray-temporariesβ warns about array temporaries the compiler generates ποΈ. That info is sometimes useful for optimisation, so you can dodge those temporaries to avoid them π‘.-Wc-binding-typeβ warns if a variable might not be C interoperable π. Especially if it's declared with an intrinsic type using the default kind, instead of a kind parameter made for C interoperability from the intrinsic"ISO_C_Binding"module π ββοΈ. This is implied by-Wallβ¨.-Wcharacter-truncationβ warns when a character assignment chops off the string being assigned βοΈ.-Wline-truncationβ warns when a source code line gets truncated π. Implied by-Wall. For free-form source code, the default is-Werror=line-truncation, so truncations get reported as errors π.-Wconversionβ warns about implicit conversions that are likely to change the value of the expression after converting π. Implied by-Wall.-Wconversion-extraβ warns about implicit conversions between different types and kinds π§©. This option does not imply-Wconversionπ .-Wdeprecated-openmpβ warns when you use deprecated OpenMP code πͺ¦.-Wexternal-argument-mismatchβ warns about argument mismatches for dummy external procedures π. This is implied by-fc-prototypes-external, because a valid C23 interface can't be generated in that case π. It's also implied by-Wall.-Wextraβ turns on some warning options for language features that can be a bit problematic πΆοΈ. That's currently-Wcompare-reals,-Wunused-parameterand-Wdo-subscriptπ.-Wfrontend-loop-interchangeβ warns when you use-ffrontend-loop-interchangeto perform loop interchanges π.-Wimplicit-interfaceβ warns if a procedure is called without an explicit interface π. Heads up: this only checks that an explicit interface is present π. It doesn't check whether the declared interfaces are consistent across program units π.-Wimplicit-procedureβ warns if a procedure is called that has neither an explicit interface nor has been declared"EXTERNAL"π« .-Winteger-divisionβ warns if a constant integer division truncates its result β. For example,3/5evaluates to0π€―.-Wintrinsics-stdβ warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (with-std), and treats it as an"EXTERNAL"procedure because of that π΅οΈ.-fall-intrinsicscan be used to never trigger this, and always link to the intrinsic regardless of the selected standard π§.-Wno-overwrite-recursiveβ doesn't warn when-fno-automaticis used with-frecursiveπ . Recursion gets broken if the relevant local variables don't have the"AUTOMATIC"attribute explicitly declared π. Use this to shush the warning when you know recursion isn't broken π€«. It's super handy for build environments that use-Werrorπ§±.-Wreal-q-constantβ warns if a real-literal-constant contains a"q"exponent letter π’.-Wsurprisingβ warns when "suspicious" code constructs turn up π«’. They're technically legal, but they usually mean an error was made π¬. Right now it warns in these situations:- An
"INTEGER"-typedSELECT CASEconstruct has aCASEthat can never be matched, because its lower value is greater than its upper value π. - A
"LOGICAL"-typedSELECT CASEconstruct has threeCASEstatements π§. - A
TRANSFERspecifies a source that's shorter than the destination π. - The type of a function result is declared more than once with the same type. If
-pedanticor standard-conforming mode is enabled, this is an error π¨. - A
"CHARACTER"variable is declared with a 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 π .) - With
-fopenacc, when named constants are used with clauses that take a variable, since doing so has no effect π.
- An
-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.-Wtabscauses a warning to be issued whenever a tab is encountered π. Heads up:-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018,-std=f2023and-WallπΈ.-Wundefined-do-loopβ warns if aDOloop with a step of either1or-1yields an underflow or an overflow while an induction variable of the loop is iterating π. Implied by-Wall.-Wunderflowβ warns when numerical constant expressions that yield an underflow are encountered during compilation π. Enabled by default β .-Wintrinsic-shadowβ warns if a user-defined procedure or module procedure has the same name as an intrinsic π₯. In that case, you might need an explicit interface, or an"EXTERNAL"or"INTRINSIC"declaration, so later calls get resolved to the intrinsic or procedure you actually want π―. Implied by-Wall.-Wuse-without-onlyβ warns if aUSEstatement has noONLYqualifier, which means it implicitly imports all public entities of the used module π¦.-Wunused-dummy-argumentβ warns about unused dummy arguments ποΈ. Implied by-Wall.-Wunused-parameterβ okay, plot twist π: unlike gcc's meaning of-Wunused-parameter, gfortran's version doesn't warn about unused dummy arguments (go check-Wunused-dummy-argumentfor that) π . It warns about unusedPARAMETERvalues instead π.-Wunused-parameteris implied by-Wextraif-Wunusedor-Wallis also used π .-Walign-commonsβ by default, gfortran warns about any occasion of variables being padded for proper alignment inside aCOMMONblock π. You can turn this 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-optimizeoption ποΈ. Implied by-Wextra.-Wrealloc-lhsβ warns when the compiler might insert code to allocate or reallocate an allocatable array variable of intrinsic type in intrinsic assignments π. In hot loops, the Fortran 2003 reallocation feature may reduce performance π’. If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g.(:,:,:)) for the variable on the left-hand side, to prevent the reallocation check β‘. Heads up: the warning can show up even when the compiler optimises reallocation checks away, for instance when the right-hand side contains the same variable multiplied by a scalar π€·. See also-frealloc-lhsπ.-Wrealloc-lhs-allβ warns when the compiler inserts code to allocate or reallocate an allocatable variable π§¬. This includes scalars and derived types.-Wcompare-realsβ warns when you compare real or complex types for equality or inequality βοΈ. Implied by-Wextra.-Wtarget-lifetimeβ warns if the pointer in a pointer assignment might outlive its target β³. Implied by-Wall.-Wzerotripβ warns if aDOloop is known to execute zero times at compile time π. Implied by-Wall.-Wdo-subscriptβ warns if an array subscript inside aDOloop could lead to an out-of-bounds access, even if the compiler can't prove that the statement is actually executed π±. Here's the kind of thing it catches:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
Implied by -Wextra.
-Werrorβ turns all warnings into errors π¨π.
Heads up bestie, some of these have no effect when you're compiling Fortran programs π so don't panic if nothing changes. π
β¨ Options for debugging your program β¨
GNU Fortran has a whole kit of special options for debugging your program π main character debugging energy, honestly.
-fdebug-aux-varsβ renames the internal variables thegfortranfront end creates and makes them visible to a debugger π. Their names start with uppercase letters followed by an underscore. It's super useful for debugging the compiler's code generation alongside-fdump-tree-original, and for debugging the executable itself with-gor-ggdb3π§.-ffpe-trap=listβ lets you pick which floating point exception traps to turn on π¨ Normally, if a floating point exception happens and its trap is enabled, aSIGFPEsignal gets sent and the program is aborted, leaving behind a core file you can debug with π.listis a (possibly empty) comma-separated list of eithernone(which clears the whole set of trapped exceptions) or any of these:invalidβ an invalid floating point operation, such asSQRT(-1.0)zeroβ division by zerooverflowβ overflow in a floating point operationunderflowβ underflow in a floating point operationinexactβ loss of precision during an operationdenormalβ an operation performed on a denormal value
The first five line up with the five IEEE 754 exceptions. denormal isn't part of IEEE 754, but it's available on some common architectures like x86 π₯οΈ.
The first three (invalid, zero, and overflow) often mean something serious went wrong. Unless your program has a plan for dealing with them, turning on traps for those three is probably a good idea π«Ά.
If you use the option more than once on the command line, the lists get joined: -ffpe-trap=list1 followed by -ffpe-trap=list2 is equivalent to -ffpe-trap=list1,list2 π.
Once an exception is enabled, it can't be disabled with a negative form (there isn't one). The only way to clear them is to clear all traps by specifying none π
ββοΈ
Most floating point operations lose some precision due to rounding, so -ffpe-trap=inexact is likely to be pretty uninteresting in practice π΄.
By default, no exception traps are enabled.
-ffpe-summary=listβ picks which floating-point exceptions get their flag status printed toERROR_UNITwheneverSTOPorERROR STOPruns πlistcan benone,all, or a comma-separated list ofinvalid,zero,overflow,underflow,inexactanddenormal. (Peek at-ffpe-trapfor what each exception means π§)- If the option shows up more than once on the command line, only the last one is used.
- By default, you get a summary for all exceptions except
inexact.
-fno-backtraceβ stops the Fortran runtime library from trying to print a backtrace when a serious runtime error or a deadly signal hits π ββοΈ That includes segmentation fault, illegal instruction, bus error, floating-point exception, and any other POSIX signals whose action is core. This option only has influence for compilation of the Fortran main program.
π Options for directory search π
These options decide how GNU Fortran hunts down files pulled in by the INCLUDE directive, and where it looks for previously compiled modules π΅οΈ They also change the search paths cpp uses when it preprocesses Fortran source.
-Idirβ affects howINCLUDEgets interpreted (and the#includedirective from the cpp preprocessor too) ποΈ- The general behaviour of
-IandINCLUDEis pretty much the same as-Iwith#includein cpp, when it comes to looking forheader.gccfiles and other stuff like that. - This path also gets searched for
.modfiles when previously compiled modules are needed by aUSEstatement.
- The general behaviour of
-Jdirβ says where to put the.modfiles for compiled modules π¦ It also gets added to the list of directories aUSEstatement searches.- The default is the current directory.
-fintrinsic-modules-path dirβ tells the compiler where the pre-compiled intrinsic modules live, if they're not in the default spot it expects π
π Influencing the linking step π
These options only come into play when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're meaningless π«
-static-libgfortranβ on systems that provide libgfortran as both a shared and a static library, this forces the static version π§ If no shared version of libgfortran was built when the compiler was configured, this option has no effect.-static-libquadmathβ same vibe, but for libquadmath π§ On systems that provide it as both shared and static, this forces the static version. If no shared version of libquadmath was built when the compiler was configured, nothing happens.- Please note that the libquadmath runtime library is licensed under the GNU Lesser General Public License (LGPL), and linking it statically introduces requirements when you redistribute the resulting binaries βοΈ
πββοΈ Influencing runtime behavior πββοΈ
These options affect the runtime behaviour of programs compiled with GNU Fortran β‘
-fconvert=conversionβ sets how data is represented in unformatted files πΎ On most systems, the valid values forconversionare:nativeβ the defaultswapβ swaps between big- and little-endianbig-endianβ uses big-endian representation for unformatted fileslittle-endianβ uses little-endian representation for unformatted files
On POWER systems that support -mabi=ieeelongdouble, there are additional options too, which can be combined with the others using commas. They are:
r16_ieeeβ uses IEEE 128-bit format forREAL(KIND=16)r16_ibmβ uses IBM long double format forREAL(KIND=16)
This option only has an effect when used in the main program. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable override the default specified by -fconvert π₯
-frecord-marker=lengthβ sets the length of record markers for unformatted files π Valid values forlengthare4and8, and the default is4. This is different from older gfortran versions, which used a default record marker length of8on most systems. If you want to read or write files compatible with earlier versions of gfortran, use-frecord-marker=8π°οΈ-fmax-subrecord-length=lengthβ sets the maximum length for a subrecord π The maximum permitted value forlengthis2147483639, which is also the default. It's only really useful for the gfortran testsuite π§ͺ-fsign-zeroβ when enabled, floating point numbers with a value of zero but the sign bit set get written as negative numbers in formatted output, and get treated as negative by theSIGNintrinsic β-fno-sign-zerodoesn't print the negative sign of zero values (or values rounded to zero for I/O), and treats zero as a positive number in theSIGNintrinsic, 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β outputs a list of the global identifiers after translating into middle-end representation π It's mostly useful for debugging the GNU Fortran compiler itself.-fdump-fortran-optimizedβ outputs the parse tree after front-end optimization π³ It's mostly useful for debugging the GNU Fortran compiler itself.-fdump-fortran-originalβ outputs the internal parse tree after translating the source program into internal representation π² It's mostly useful for debugging the GNU Fortran compiler itself.
For-fdump-fortran-global,-fdump-fortran-optimizedand-fdump-fortran-original, the output might change between releases, and the option may also generate internal compiler errors for features that have only recently been added. π¬
-fdump-parse-treeβ outputs the internal parse tree after translating the source program into internal representation π³ It's mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also generate internal compiler errors for features that have only recently been added.- This option is deprecated; use
-fdump-fortran-originalinstead β οΈ
- This option is deprecated; use
-save-tempsβ stores the usual "temporary" intermediate files permanently, naming them as auxiliary output files, as described under GCC-dumpbaseand-dumpdirπΎ
gfortran -save-temps -c foo.F90
This preprocesses the 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. The list below only shows one of the forms, the one that is not the default. You can figure out the other form by either removing no- or adding it π§©
-fno-automaticβ treats each program unit (except those marked asRECURSIVE) as if theSAVEstatement were specified for every local variable and array referenced in it π§· It does not affect common blocks. (Some Fortran compilers provide this option under the name-staticor-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-frecursiveto use no static memory π§- Local variables or arrays having an explicit
SAVEattribute are silently ignored unless the-pedanticoption is added π€«
- Local variables or arrays having an explicit
-ff2cβ okay bestie, this one is for the vintage crowd π§ It makes your code vibe with the stuff compiled by g77 and f2c β¨ It generates code designed to be compatible with code generated by g77 and f2c.
The g77 calling conventions (originally from f2c) are a little extra. Functions that return default REAL have to actually return the C type double, and functions that return COMPLEX send their value back through an extra argument in the calling sequence, which points to where the result gets stored π
Under the default GNU calling conventions, it's a different energy. Default REAL functions just return the C type float, and COMPLEX functions return the GNU C type complex, same as they would in GNU C π Also, -ff2c implies -fsecond-underscore, unless you explicitly ask for -fno-second-underscore π«Ά
This doesn't change the code that interfaces with the libgfortran library πΈ
β οΈ Caution, bestie: it's not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions! CallingCOMPLEXor defaultREALfunctions between program parts compiled with different calling conventions will break at execution time π
β οΈ Caution: this breaks code that passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, because the library implementations use the-fno-f2ccalling conventions π
-fno-underscoringβ no appended underscores for you! π ββοΈ It tells GNU Fortran not to transform names of entities from your Fortran source by adding underscores to them.
Normally, with -funderscoring in effect, GNU Fortran tacks one underscore onto external names. That's so the code plays nice with lots of UNIX Fortran compilers π¦ This doesn't apply to names declared with C binding, or to names within a module.
β οΈ Caution: the default behavior of GNU Fortran is incompatible with f2c and g77. If you want your object files to be compatible with object code made by these tools, use the -ff2c option π
Honestly, using -fno-underscoring isn't recommended unless you're experimenting with stuff like fitting GNU Fortran into existing system environments (think existing libraries, tools, and so on) π§ͺ
Here's the tea. Say j() and max_count() are external functions, while my_var and lvar are local variables. A Fortran statement like this:
I = J() + MAX_COUNT (MY_VAR, LVAR)
gets implemented as something akin to this C code:
i = j_() + max_count_(&my_var, &lvar);
But with -fno-underscoring, the same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
So -fno-underscoring lets you use your own names directly while debugging, and when you're interfacing GNU Fortran code with other languages π
Quick reality check though: just because the names match doesn't mean the interface GNU Fortran uses for an external name matches the interface some other language uses for that same name. Getting GNU Fortran code to link to code from another compiler, by this or any other method, can be just a small part of the whole deal. Getting both compilers to agree on stuff besides naming can take serious effort, and unlike naming disagreements, linkers normally can't detect disagreements in those other areas π₯²
Also, with -fno-underscoring, the lack of appended underscores creates a very real possibility that a user-defined external name conflicts with a name in a system library π° That could make finding unresolved-reference bugs super hard in some cases. They might only happen at program run time and show up as buggy behavior at run time.
Last thing: 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 in this section π
-fsecond-underscoreβ the double-underscore glow-up π By default, GNU Fortran appends an underscore to external names. If you use this option, GNU Fortran appends two underscores to names that already have underscores, and one underscore to 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 it's implied by use of the -ff2c option π§
This option has no effect if -fno-underscoring is in effect. It's implied by the -ff2c option too πΈ
-fcoarray=<keyword>β coarray support, but make it a choice π Here are the keywords:noneβ disables coarray support! Using coarray declarations and image-control statements produces a compile-time error. (Default)singleβ single-image mode, sonum_images()is always one 1οΈβ£libβ library-based coarray parallelization π A suitable GNU Fortran coarray library, such as<http://opencoarrays.org>, needs to be linked. Alternatively, GCC'slibcaf_singlelibrary can be linked, albeit it only supports a single image.
-fcheck=<keyword>β turns on run-time checks, the ultimate safety net πΈοΈ The argument has to be a comma-delimited list of the keywords below. Prefixing a check withno-disables it if it was activated by a previous specification πallβ enables all run-time tests of-fcheck.array-tempsβ warns at run time when, for passing an actual argument, a temporary array had to be generated. The info from this warning is sometimes useful for optimization, so you can avoid such temporaries π§Ή- Note: the warning is only printed once per location.
bitsβ enables generation of run-time checks for invalid arguments to the bit manipulation intrinsics π’boundsβ enables 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 makes sure all string lengths are equal for character array constructors without an explicit typespec.- Some checks require that
-fcheck=boundsis 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.
- Some checks require that
doβ enables generation of run-time checks for invalid modification of loop iteration variables πmemβ enables generation of run-time checks for memory allocation π§- Note: this option does not affect explicit allocations using the
ALLOCATEstatement, which are always checked.
- Note: this option does not affect explicit allocations using the
pointerβ enables generation of run-time checks for pointers and allocatables πrecursionβ enables generation of run-time checks for recursively called subroutines and functions that aren't marked as recursive. See also-frecursive.- Note: this check does not work for OpenMP programs, and it's disabled if used together with
-frecursiveand-fopenmp.
- Note: this check does not work for OpenMP programs, and it's disabled if used together with
Example time! 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 for the warnings about generated array temporaries β¨
-fbounds-checkβ a deprecated alias for-fcheck=bounds. Retired, but still in the group chat π»-ftail-call-workaround,-ftail-call-workaround=nβ okay, this one is a whole mood π€ Some C interfaces to Fortran code violate the gfortran ABI by omitting the hidden character length arguments as described in (the page cuts off right there, bestie π). 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 only disabled in gfortran procedures with character arguments that call implicitly prototyped procedures π§©
β οΈ Warning: using this option can lead to problems, including crashes due to insufficient stack space.
It is very strongly recommended to fix the code in question π« The -fc-prototypes-external option can be used to generate prototypes that conform to gfortran's ABI, for inclusion in the source code.
Support for this option will likely be withdrawn in a future release of gfortran π
The negative form, -fno-tail-call-workaround or the equivalent -ftail-call-workaround=0, can be used to disable this option.
Default is currently -ftail-call-workaround, but this will change in future releases.
-fcheck-array-temporariesβ a deprecated alias for-fcheck=array-temps. Same vibes, new name π¦-fmax-array-constructor=nβ need a bigger array constructor? This option raises 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β the stack size limit for arrays π₯ This option specifies the size in bytes of the largest array that gets put on the stack. If the size is exceeded, static memory is used instead (except in procedures marked asRECURSIVE). Use the option-frecursiveto allow for recursive procedures that don't have aRECURSIVEattribute, or for parallel programs. Use-fno-automaticto never use the stack π
This option currently only affects local arrays declared with constant bounds, and it may not apply to all character variables. Future versions of GNU Fortran may improve this behavior π±
The default value for n is 65536.
-fstack-arraysβ puts all arrays of unknown size, plus array temporaries, onto stack memory π₯³ If your program uses very large local arrays, you might have to extend your runtime limits for stack memory on some operating systems. This flag is enabled by default at optimization level-Ofast, unless-fmax-stack-var-sizeis specified ποΈ-fpack-derivedβ okay bestie, this one tells GNU Fortran to pack derived type members as closely as possible π¦β¨. Heads up though: code compiled with it is likely to be incompatible with code compiled without it, and it may execute slower π.-frepack-arraysβ ngl this one is a whole mood πΈ. Sometimes GNU Fortran passes assumed shape array sections using a descriptor that describes a noncontiguous area of memory. With this flag, it adds code to the function prologue that repacks the data into a contiguous block at runtime π§. That should make accesses to the array faster, BUT it can add significant overhead to the function call, especially when the passed data is noncontiguous π.-fshort-enumsβ this one's all about interop π€. It exists so you can play nice with C code that was compiled with-fshort-enums. GNU Fortran picks the smallestINTEGERkind that a given enumerator set fits in, then gives all of its enumerators that kind π.-finline-arg-packingβ okay, this one is a little spicy πΆοΈ. When you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size argument, or as an argument to a procedure that doesn't have an explicit interface, that argument may have to be packed, which means shoved into contiguous memory π¦. The classic example is the call tofooin this little snippet:
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
With -finline-arg-packing in effect, that packing is done by inline code π₯. That allows for more optimization, but the code size goes up π.
-finline-arg-packing is implied by any of the -O options, except when you're optimizing for size with -Os. If your code has a very large number of arguments that have to be packed, the code size and compilation time can get excessive π. If that's the case, it may be better to disable this option. You can find where packing happens by using -Warray-temporaries.
-fexternal-blasβ this one hands the heavy lifting to someone else π. It makes gfortran generate calls to BLAS functions for some matrix operations likeMATMUL, instead of using its own algorithms, as long as the matrices involved are larger than a given limit (see-fblas-matmul-limit). This can be a win if an optimized vendor BLAS library is available. The BLAS library has to be specified at link time. This option specifies a BLAS library with integer arguments of default kind (32 bits). It cannot be used together with-fexternal-blas64.-fexternal-blas64β same energy as the one above, just bigger π¦. gfortran generates calls to BLAS functions for some matrix operations likeMATMUL, instead of its own algorithms, if the matrices are larger than a given limit (see-fblas-matmul-limit). This may be profitable if an optimized vendor BLAS library is available, and the BLAS library has to be specified at link time. This one specifies a BLAS library with integer arguments ofKIND=8(64 bits). It cannot be used together with-fexternal-blas, and it requires a 64-bit system. It also requires-ffrontend-optimize.-fblas-matmul-limit=nβ only matters when-fexternal-blasor-fexternal-blas64is in effect π. Matrix multiplication of matrices with a size larger than or equal tongets handed off to BLAS functions, while smaller ones are handled by gfortran's internal algorithms. If the matrices involved aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices.
The default value for n is 30.
-finline-intrinsics,-finline-intrinsics=intr1,intr2,...β okay this one is giving "you pick the vibe" π§. It tells the compiler to prefer generating inline code over calls to libgfortran functions when implementing intrinsics.
Intrinsics can be implemented either by calling a libgfortran library function or by generating inline code directly. For most intrinsics there's only one variant, so there's no choice to make. Some intrinsics can use either a library function or inline code, and inline code usually leaves room for extra optimization over a library function. With -finline-intrinsics=... or -fno-inline-intrinsics=..., the choice only applies to the intrinsics in the comma-separated list you give as the argument.
For each intrinsic, if neither flag variant made a choice, the default depends on optimization: library calls get generated when you're not optimizing or when you're optimizing for size, and otherwise inline code is preferred β¨.
The intrinsics you can pass to -finline-intrinsics= are currently limited to MAXLOC and MINLOC. The effect is also limited to calls of those intrinsics without a DIM argument and with an ARRAY of a non-CHARACTER type. The rank-1 case with a DIM argument present, i.e. MAXLOC(A(:),DIM=1) or MINLOC(A(:),DIM=1), is inlined unconditionally for a numeric rank-1 array argument A π
.
-finline-matmul-limit=nβ when front-end optimization is active, some calls to theMATMULintrinsic function get inlined π¦. This can increase code size if the size of the matrix can't be determined at compile time, since code for both cases gets generated. Setting-finline-matmul-limit=0disables inlining in all cases. Setting it to a value ofnproduces inline code for matrices with a size up ton. If the matrices involved aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices.
The default value for n is 30. The -fblas-matmul-limit can be used to change this value.
-frecursiveβ allows indirect recursion by forcing all local arrays to be allocated on the stack π. This flag can't be used together with-fmax-stack-var-size=or-fno-automatic.-finit-local-zeroβ the initialization main character π. It tells the compiler to initialize localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes. If you want finer control, there are more options:-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>(which also initializes the real and imaginary parts of localCOMPLEXvariables),-finit-logical=<true|false>, and-finit-character=n(wherenis an ASCII character value).-finit-derivedβ components of derived type variables get initialized according to these flags π§Έ. Components whose type isn't covered by an explicit-finit-*flag are treated as described above with-finit-local-zero.-finit-integer=nβ this one parses the value into an integer of typeINTEGER(kind=C_LONG)on the host π’. That value then gets assigned to the integer variables in your Fortran code. If the value is too large for the kind, it might wrap around π¬.-finit-real=<zero|inf|-inf|nan|snan>β initializesREALandCOMPLEXvariables with a quiet NaN π«Ά. For a signalling NaN, use-finit-real=snan.
Be careful withsnan! Compile-time optimizations may convert signalling NaNs into quiet NaNs, and trapping needs to be enabled (e.g. via-ffpe-trap).
-finit-logical=<true|false>β setsLOGICALvariables to the value you pick β .-finit-character=nβ setsCHARACTERvariables to the ASCII character valuenπ€.
Okay, but these options do NOT initialize:
- objects with the
POINTERattribute - allocatable arrays
- variables that appear in an
EQUIVALENCEstatement
(These limitations may be removed in future releases.)
Heads up: enabling any of the-finit-*options silences warnings that would have been emitted by-Wuninitializedfor the affected local variables π.
-falign-commonsβ by default, gfortran enforces proper alignment of all variables in aCOMMONblock by padding them as needed π. On some platforms this is mandatory, and on others it increases performance. If aCOMMONblock isn't declared with consistent data types everywhere, this padding can cause trouble, and-fno-align-commonscan be used to turn off the automatic alignment. Use the same form of this option for all files that share aCOMMONblock. To avoid potential alignment issues inCOMMONblocks, it's recommended to order objects from largest to smallest π.-fno-protect-parensβ by default, parentheses in expressions are honored at all optimization levels, so the compiler doesn't do any reassociation π. Using-fno-protect-parenslets the compiler reorderREALandCOMPLEXexpressions to produce faster code.
For the reassociation optimization,-fno-signed-zerosand-fno-trapping-mathneed to be in effect too. The parentheses protection is enabled by default, unless-Ofastis given.
-frealloc-lhsβ an allocatable left-hand side of an intrinsic assignment is automatically (re)allocated if it's either unallocated or has a different shape π§. This option is enabled by default except when-std=f95is given. See also-Wrealloc-lhs.-faggressive-function-eliminationβ functions with identical argument lists get eliminated within statements, whether or not they're markedPUREπ‘οΈ. For example, in this line:
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 one performs front-end optimization by manipulating parts of the Fortran parse tree π. It's enabled by default by any-Ooption except-O0and-Og. The optimizations enabled by this option include:- inlining calls to
MATMUL - elimination of identical function calls within expressions
- removing unnecessary calls to
TRIMin comparisons and assignments - replacing
TRIM(a)witha(1:LEN_TRIM(a)) - short-circuiting of logical operators (
.AND.and.OR.)
- inlining calls to
It can be deselected by specifying -fno-frontend-optimize π
ββοΈ.
-ffrontend-loop-interchangeβ attempts to interchange loops in the Fortran front end wherever it's profitable π. It's enabled by default by any-Ooption. Right now, this option only affectsFORALLandDO CONCURRENTstatements with several forall triplets.
πΈ ENVIRONMENT πΈ
okay so gfortran is lowkey chill about env vars π
It doesn't use any environment variables to control its operation beyond the ones that already affect gcc. So if you're already tweaking gcc's env vars, gfortran is gonna listen to those too β¨
π¦ BUGS π¦
found a bug?! π bestie, the instructions for reporting it live in <file:///usr/share/doc/gcc-16/README.Bugs> π go read that before you file anything π
π₯ SEE ALSO π₯
if you want more, these are absolutely worth your time:
gpl(7),gfdl(7),fsf-funding(7)πcpp(1),gcov(1),gcc(1),as(1),ld(1),gdb(1),dbx(1)π§- the Info entries for
gcc,cpp,gfortran,as,ld,binutilsandgdbπ
π AUTHOR π
the people who built GCC and GNU Fortran are all listed in the Info entry for gfortran π«Ά that's where the whole crew gets their credit.
π COPYRIGHT π
Copyright (c) 2004-2026 Free Software Foundation, Inc. πΈ
so you're allowed to copy, distribute and/or modify this doc under the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation π The Invariant Sections are "Funding Free Software", the Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). A copy of the license is included in the gfdl(7) man page π¦
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.
And that's the whole page, bestie! π§ This one comes from the gcc-16 docs and was last dated 2026-03-22 π Stay curious, stay slay π β¨
π¦ where this page comes from
- ubuntu resolute: gfortran-16-m68k-linux-gnu 16-20260322-1ubuntu1cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms