GFORTRAN(1)
๐ GFORTRAN(1) ๐
Okay bestie, this is the GNU manual page for GFORTRAN(1), so grab your snacks ๐โจ
โจ NAME โจ
gfortran is the GNU Fortran compiler ๐
๐ฆ SYNOPSIS ๐ฆ
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
Heads up: the synopsis only shows the most useful options, and the rest are waiting for you further down ๐ง
๐ DESCRIPTION ๐
The gfortran command is literally a queen. It supports all the options that the gcc command supports ๐ Only the options that are specific to GNU Fortran get documented here, so you don't have to read the same stuff twice.
Every GCC and GNU Fortran option works with both gfortran and gcc, plus any other drivers that got built at the same time, like g++. Adding GNU Fortran to the GCC distribution means all the relevant drivers accept GNU Fortran options, so it's giving teamwork ๐ซถ
Some options come in positive and negative forms. The negative form of -ffoo is -fno-foo. This manual only documents whichever of the two forms is not the default, so keep that in mind ๐
๐ธ OPTIONS ๐ธ
Here's the full tea on every option that's specific to GNU Fortran, sorted into groups by type. The explanations come after the lists โจ
๐ Fortran Language Options
-fall-intrinsics -fallow-argument-mismatch -fallow-invalid-boz
-fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments
-fdec -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints
-fdec-static -fdec-math -fdec-include -fdec-format-defaults
-fdec-blank-format-item -fdefault-double-8 -fdefault-integer-8
-fdefault-real-8 -fdefault-real-10 -fdefault-real-16 -fdollar-ok
-ffixed-line-length-n -ffixed-line-length-none -fpad-source
-ffree-form -ffree-line-length-n -ffree-line-length-none
-fimplicit-none -finteger-4-integer-8 -fmax-identifier-length
-fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp
-freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10
-freal-8-real-16 -freal-8-real-4 -std=std -ftest-forall-temp
๐ฅ Preprocessing Options
-A-question[=answer] -Aquestion=answer -C -CC -Dmacro[=defn] -H -P
-Umacro -cpp -dD -dI -dM -dN -dU -fworking-directory -imultilib dir
-iprefix file -iquote -isysroot dir -isystem dir -nocpp -nostdinc
-undef
๐ Error and Warning Options
-Waliasing -Wall -Wampersand -Warray-bounds -Wc-binding-type
-Wcharacter-truncation -Wconversion -Wdo-subscript
-Wfunction-elimination -Wimplicit-interface -Wimplicit-procedure
-Wintrinsic-shadow -Wuse-without-only -Wintrinsics-std
-Wline-truncation -Wno-align-commons -Wno-overwrite-recursive
-Wno-tabs -Wreal-q-constant -Wsurprising -Wunderflow
-Wunused-parameter -Wrealloc-lhs -Wrealloc-lhs-all
-Wfrontend-loop-interchange -Wtarget-lifetime -fmax-errors=n
-fsyntax-only -pedantic -pedantic-errors
๐ Debugging Options
-fbacktrace -fdump-fortran-optimized -fdump-fortran-original
-fdebug-aux-vars -fdump-fortran-global -fdump-parse-tree
-ffpe-trap=list -ffpe-summary=list
๐ Directory Options
-Idir -Jdir -fintrinsic-modules-path dir
๐ Link Options
-static-libgfortran
โฑ๏ธ Runtime Options
-fconvert=conversion -fmax-subrecord-length=length
-frecord-marker=length -fsign-zero
๐ค Interoperability Options
-fc-prototypes -fc-prototypes-external
๐ ๏ธ Code Generation Options
-faggressive-function-elimination -fblas-matmul-limit=n
-fbounds-check -ftail-call-workaround -ftail-call-workaround=n
-fcheck-array-temporaries
-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>
-fcoarray=<none|single|lib> -fexternal-blas -ff2c
-ffrontend-loop-interchange -ffrontend-optimize -finit-character=n
-finit-integer=n -finit-local-zero -finit-derived
-finit-logical=<true|false> -finit-real=<zero|inf|-inf|nan|snan>
-finline-matmul-limit=n -finline-arg-packing
-fmax-array-constructor=n -fmax-stack-var-size=n -fno-align-commons
-fno-automatic -fno-protect-parens -fno-underscoring
-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive
-frepack-arrays -fshort-enums -fstack-arrays
๐ญ Options controlling Fortran dialect
Okay so these options are the ones that control the exact flavor of Fortran the compiler accepts ๐ฆ
-ffree-form,-ffixed-formโ These pick the layout of the source file. Free form came along in Fortran 90, while fixed form is the classic look that older Fortran programs were written in. If you don't pick either one, the compiler figures out the source form from the file extension, which is kind of iconic of it ๐-fall-intrinsicsโ This makes the compiler accept every intrinsic procedure, GNU-specific extensions included, so you get the whole intrinsics buffet โจ It's super handy with-std=f95if you want standard compliance but still want full gfortran access. The catch:-Wintrinsics-stdgets ignored, and no user-defined procedure that shares a name with an intrinsic will be called unless it's explicitly declaredEXTERNAL๐-fallow-argument-mismatchโ Some code calls external procedures with mismatched arguments, either against the procedure's definition or against other calls. That code isn't conforming, and it usually gets flagged as an error. This option downgrades that error to a warning, and the only way to switch that warning off is to disable all warnings with-w. Only one occurrence per argument gets flagged. This option is implied by-std=legacy๐
Using this option is strongly discouraged, bestie ๐ซ You can write standard-conforming code that allows different argument types by using an explicit interface and TYPE(*), so there's zero reason to lean on this one.
-fallow-invalid-bozโ A BOZ literal constant can only show up in a few contexts in standard-conforming Fortran. This option turns the error into a warning and lets a BOZ literal constant appear where the Fortran standard would normally ban it ๐-fd-lines-as-code,-fd-lines-as-commentsโ These give special treatment to lines that start withdorDin fixed form sources. With-fd-lines-as-code, those lines get treated as if their first column held a blank. With-fd-lines-as-comments, they get 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's). Heads up, though: these features are non-standard and should be avoided at all costs ๐ For details on how GNU Fortran implements these extensions, check the full documentation. Other flags that 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-commentsaren't set, 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, which is in addition to%. 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 the complete list of intrinsics, see the full documentation ๐งฎ-fdec-mathโ This enables legacy math intrinsics likeCOTANand the degree-valued trig functions (likeTAND,ATAND, and so on), so older code keeps working ๐-fdec-staticโ This enables DEC-styleSTATICandAUTOMATICattributes, which let you explicitly specify the storage of variables and other objects ๐ฆ-fdec-includeโ This letsINCLUDEbe parsed as a statement in addition to parsing it as anINCLUDEline. When it's parsed as a statement, theINCLUDEdoesn't have to sit on a single line and can use line continuations โจ-fdec-format-defaultsโ This lets the format specifiersF,G, andIget used without width specifiers, and 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$are rejected, because it's unclear which implicit typing rules should apply since different vendors do different things. Using$inIMPLICITstatements is also rejected ๐ซ-fbackslashโ This changes how backslashes work in string literals. Instead of a single backslash character, you get "C-style" escape characters. These combos get expanded:"\a"(alert),"\b"(backspace),"\f"(form feed),"\n"(newline),"\r"(carriage return),"\t"(horizontal tab),"\v"(vertical tab),"\\"(backslash), and"\0"(NUL). On top of that,"\x"nn,"\u"nnnn, and"\U"nnnnnnnn(where eachnis a hexadecimal digit) get translated into the Unicode characters for those code points ๐ Every other combo of a character preceded by\stays unexpanded.-fmodule-privateโ This sets the default accessibility of module entities toPRIVATE. Use-associated entities won't be accessible unless they're explicitly declaredPUBLIC๐-ffixed-line-length-nโ This sets the column after which characters get ignored in typical fixed-form lines. Unless you use-fno-pad-source, it also sets the column through which spaces are assumed (as if the line were padded to that length) after the ends of short fixed-form lines ๐ Popular values 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 have implicit spaces appended to fill out the line.-ffixed-line-length-0does the exact same thing as-ffixed-line-length-none๐-fno-pad-sourceโ By default, fixed-form lines have spaces assumed (as if padded to that length) after the ends of short fixed-form lines. That doesn't happen if you use-ffixed-line-length-0,-ffixed-line-length-none, or-fno-pad-source. With any of those options, continued character constants never get implicit spaces appended to them to fill out the line ๐ง-ffree-line-length-nโ okay so this sets the column where gfortran stops caring about a typical free-form source line, and everything past it gets ignored ๐ The default is 132. You can passnasnoneso the entire line counts, and-ffree-line-length-0is the exact same thing as-ffree-line-length-none๐ฆ-fmax-identifier-length=nโ sets the longest identifier name you're allowed to use ๐ง Typical values are 31 (Fortran 95) and 63 (Fortran 2003 and Fortran 2008) โจ-fimplicit-noneโ no implicit typing allowed, unless you override it with explicitIMPLICITstatements ๐ It's basically the same as slappingimplicit noneat the top of every procedure ๐ฅ-fcray-pointerโ turns on the Cray pointer extension, which gives you C-style pointer vibes ๐ธ-fopenaccโ enables the OpenACC extensions ๐ That means!$accdirectives in free form, andc$acc,*$accand!$accdirectives in fixed form. It also covers the!$conditional compilation sentinels in free form, andc$,*$and!$sentinels in fixed form. And when you link, the OpenACC runtime library gets linked in too ๐ซถ-fopenmpโ enables the OpenMP extensions ๐ That means!$ompdirectives in free form, andc$omp,*$ompand!$ompdirectives in fixed form. It also covers the!$sentinels in free form, andc$,*$and!$sentinels in fixed form, and linking pulls in the OpenMP runtime library. This option implies-frecursive๐ฅ-fno-range-checkโ turns off range checking on the results of simplifying constant expressions at compile time ๐ Normally GNU Fortran errors out on something likea = 1. / 0. With this option there's no error, andagets+Infinity. If an expression evaluates to something outside the relevant range["-HUGE()":HUGE()], it gets replaced by-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โ the default integer and logical types become 8 bytes wide ๐ข This also changes the kind of integer constants like42. Unlike-finteger-4-integer-8, it does not promote variables with an explicit kind declaration.-fdefault-real-8โ the default real type becomes 8 bytes wide ๐ This also affects the kind of non-double real constants like1.0. It bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. If you pass-fdefault-double-8along withfdefault-real-8, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-8,fdefault-real-8doesn't promote variables with explicit kind declarations.-fdefault-real-10โ same energy, but the default real type becomes a 10 byte wide type ๐ง This also affects the kind of non-double real constants like1.0. It bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. If you pass-fdefault-double-8along withfdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-10,fdefault-real-10doesn't promote variables with explicit kind declarations.-fdefault-real-16โ the default real type becomes a 16 byte wide type ๐ This also affects the kind of non-double real constants like1.0. It bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. If you pass-fdefault-double-8along withfdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-16,fdefault-real-16doesn't 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'll get an error.
๐จ This one should be used with care, and it may not suit your codes. Watch out for 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'll get an error. The-freal-4-flags also affect the default real kind, and the-freal-8-flags affect the double-precision real kind. Every other real-kind type is left alone. 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 they may not suit your codes. 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.
-std=stdโ pick the standard your program is expected to follow ๐ The options aref95,f2003,f2008,f2018,gnu, orlegacy.gnuโ the default ๐ It's a superset of the latest Fortran standard that includes every extension GNU Fortran supports. You'll still get warnings for obsolete extensions that aren't recommended for new code.legacyโ basically the same asgnu, just without those warnings for obsolete extensions. It's handy for old non-standard programs ๐งf95,f2003,f2008,f2018โ strict conformance to the Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 standards, respectively ๐ฏ You get errors for every extension beyond the relevant language standard, and warnings for the Fortran 77 features that are still permitted but obsolescent in later standards.- > ๐จ The deprecated
-std=f2008tsacts as an alias for-std=f2018. It only exists for backwards compatibility with earlier gfortran versions, so please don't use it any more ๐
-ftest-forall-tempโ a test coverage booster ๐งช It forces mostforallassignments to use a temporary.
๐ Enable and customize preprocessing ๐
Preprocessor related options ๐งฉ For more detailed info on preprocessing in gfortran, check out the section called Preprocessing and conditional compilation.
-cpp,-nocppโ-cppturns preprocessing on ๐ธ The preprocessor gets invoked automatically if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08. Use this flag to manually enable preprocessing for any kind of Fortran file.- To turn preprocessing off for files with any of those extensions, use the negative form
-nocpp๐ โโ๏ธ - The preprocessor runs in traditional mode. Restrictions on the file format, especially the line length limits, apply to preprocessed output too, so it might be a good idea to use
-ffree-line-length-noneor-ffixed-line-length-none๐
- To turn preprocessing off for files with any of those extensions, use the negative form
-dMโ instead of the normal output, you get a list of#definedirectives for all the macros defined while the preprocessor ran, including the predefined ones ๐ This is a great way to find out what's predefined in your version of the preprocessor. Assuming you have no filefoo.f90, run:
touch foo.f90; gfortran -cpp -E -dM foo.f90
and it'll show all the predefined macros โจ
-dDโ like-dM, except it doesn't 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 it only emits the macro names, not their expansions ๐ซง-dUโ likedDexcept only macros that are expanded, or whose definedness is tested in preprocessor directives, get output ๐ฆ The output is delayed until the macro is used or tested, and#undefdirectives are also output for macros that were tested but undefined at the time.-dIโ outputs#includedirectives in addition to the result of preprocessing ๐-fworking-directoryโ enables linemarkers in the preprocessor output so the compiler knows the current working directory at preprocessing time ๐บ๏ธ When this is on, the preprocessor emits a second linemarker after the initial one, containing the current working directory followed by two slashes. GCC uses that directory, when it's present in the preprocessed input, as the directory it emits as the current working directory in some debugging information formats. This option 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 are emitted whatsoever ๐-idirafterdir โ searches dir for include files, but only after all the directories specified with-Iand the standard system directories have been exhausted ๐ dir is treated as a system include directory. If dir begins with=, then that=gets replaced by the sysroot prefix; see--sysrootand-isysroot๐ง
-imultilib dir โ โจ Okay so this one lets you point to a dir that becomes a subdirectory of the folder holding the target-specific C++ headers. Very niche, very bestie-only ๐ง
-iprefix prefixโ ๐ธ This sets the prefix for any-iwithprefixoptions that come after it. If your prefix is a directory, don't forget the final/๐-isysroot dirโ ๐บ๏ธ This one is basically a sibling of--sysroot, but it only touches header files. Go check the--sysrootoption for the full tea โ-iquote dirโ ๐ฆ This searches dir only for headers pulled in with#include "file". It skips#include <file>entirely, and it runs before all the-Idirectories and the standard system directories. If dir starts with=, that=gets swapped out for the sysroot prefix. See--sysrootand-isysroot๐-isystem dirโ โญ This searches dir for headers after all the-Idirectories but before the standard system ones. It also gets marked as a system directory, so it gets the same VIP treatment as the standard system dirs. Same deal with=: if dir begins with=, it's replaced by the sysroot prefix. See--sysrootand-isysroot๐-nostdincโ ๐ Don't search the standard system directories for headers at all. Only the-Idirectories get checked (plus the directory of the current file, if that's relevant) ๐ซถ-undefโ ๐งผ Don't predefine any system-specific or GCC-specific macros. The standard predefined macros stay put, so they're still defined โจ-Apredicate=answerโ ๐ This makes an assertion with the predicate predicate and the answer answer. It's the preferred version over the older-A predicate(answer)form, which still works, but this one is way better because it doesn't use shell special characters ๐-A-predicate=answerโ ๐๏ธ Cancels an assertion with the predicate predicate and the answer answer. Bye bye ๐-Cโ ๐ฌ Don't throw out comments! Every comment gets passed through to the output file, except comments inside processed directives, which get deleted along with their directive.
Heads up, though: using -C has side effects, because the preprocessor starts treating comments as tokens in their own right. For example, a comment sitting at the start of what would be a directive line turns that line into an ordinary source line, since the first token is no longer a # ๐ญ
โ ๏ธ Warning: this currently handles C-style comments only. The preprocessor doesn't recognize Fortran-style comments yet.
-CCโ ๐ฌ๐ฌ Also don't discard comments, including during macro expansion. It's like-C, except comments inside macros get passed through to the output wherever the macro is expanded.
On top of everything -C does, -CC converts all C++-style comments inside a macro into C-style comments. Why? So using that macro later can't accidentally comment out the rest of your source line ๐ This one is mostly used to support lint comments.
โ ๏ธ Warning: this currently handles C- and C++-style comments only. The preprocessor doesn't recognize Fortran-style comments yet.
-Dnameโ ๐ Predefines name as a macro, with the definition1.-Dname=definitionโ ๐ The contents of definition get tokenized and processed as if they showed up during translation phase three in a#definedirective. Heads up that the definition gets cut off at any embedded newline characters.
If you're calling the preprocessor from a shell (or something shell-like), you might need the shell's quoting syntax to protect characters like spaces, since they mean something to the shell too.
Want a function-like macro on the command line? Write its argument list with surrounding parentheses before the equals sign (if there is one). Parentheses matter to most shells, so you'll need to quote the whole option. With sh and csh, "-D'name(args...)=definition'" works ๐ง
-D and -U options get processed in the order you give them on the command line. All -imacros file and -include file options get processed after every -D and -U ๐ซถ
-Hโ ๐ Prints the name of each header file used, on top of all the usual stuff. Each name is indented to show how deep it sits in the#includestack, which is lowkey so helpful for tracking down nested includes ๐-Pโ ๐ซ Inhibits the generation of linemarkers in the preprocessor output. This might be useful when you're running the preprocessor on something that isn't C code and will be sent to a program that could get confused by the linemarkers ๐ธ-Unameโ ๐งน Cancels any previous definition of name, whether it was built in or provided with a-Doption.
๐จ Options to request or suppress errors and warnings ๐จ
Okay, let's talk about the difference between errors and warnings, because it matters ๐
Errors are diagnostic messages saying the GNU Fortran compiler cannot compile that piece of source code. The compiler keeps going anyway, trying to report more errors to help you debug, but it won'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, warnings don't stop your program from compiling ๐ฆ
You can request lots of specific warnings with options that begin with -W. For example, -Wimplicit asks for warnings on implicit declarations. Each of these specific warning options also has a negative form starting with -Wno- to turn the warnings off, like -Wno-implicit. This manual only lists one of the two forms, whichever one is not the default โจ
These options control how many errors and warnings GNU Fortran produces, and what kinds they are:
-fmax-errors=nโ ๐ Limits the number of error messages to n. Once that limit is hit, GNU Fortran bails out instead of trying to keep processing the source code. If n is0, there's no limit on how many error messages get produced.-fsyntax-onlyโ ๐ง Checks the code for syntax errors, but doesn't actually compile it. This will generate module files for each module present in the code, but no other output file.-Wpedantic,-pedanticโ ๐ Issues warnings for uses of extensions to Fortran.-pedanticalso applies to C-language constructs when they show up in GNU Fortran source files, such as using\ein a character constant inside a directive like#include.
Valid Fortran programs should compile properly with or without this option. Without it, certain GNU extensions and traditional Fortran features are still supported. With it, a lot of those get rejected ๐
Some users try to use -pedantic to check programs for conformance, and they soon find it doesn't quite do what they want. It finds some nonstandard practices, but not all of them. Improvements to GNU Fortran in this area are welcome, though ๐
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018.
-pedantic-errorsโ ๐จ Like-pedantic, except errors get produced instead of warnings. Serious energy.-Wallโ ๐ Enables commonly used warning options for usage that we recommend avoiding, and that we believe are easy to avoid. This currently includes-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop๐ฅ-Waliasingโ ๐ Warns about possible aliasing of dummy arguments. Specifically, it warns if the same actual argument is associated with a dummy argument withINTENT(IN)and a dummy argument withINTENT(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. The warning is given with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008and-std=f2018.
Note: if there's no ampersand in a continued character constant, GNU Fortran assumes continuation happens at the first non-comment, non-whitespace character after the ampersand that started the continuation ๐ซถ
-Warray-temporariesโ ๐งบ Warns about array temporaries generated by the compiler. The info from this warning can be useful for optimization, so you can avoid those temporaries.-Wc-binding-typeโ ๐ Warns if a variable might not be C interoperable. In particular, it warns if the variable was declared using an intrinsic type with the default kind, instead of using a kind parameter defined for C interoperability in the intrinsicISO_C_Bindingmodule. This option is implied by-Wall๐-Wcharacter-truncationโ โ๏ธ Warns when a character assignment will truncate the assigned string.-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 errors ๐ญ-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 that may be problematic. This currently includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeโ ๐ Warns when using-ffrontend-loop-interchangeto perform loop interchanges.-Wimplicit-interfaceโ ๐ต๏ธ Warns if a procedure is called without an explicit interface. Note that this only checks that an explicit interface is present. It doesn't check that the declared interfaces are consistent across program units.-Wimplicit-procedureโ ๐ซฃ Warns if a procedure is called that has neither an explicit interface nor has been declared as"EXTERNAL".-Winteger-divisionโ โ Warns if a constant integer division truncates its result. As an example,3/5evaluates to0. Math is not mathing ๐-Wintrinsics-stdโ okay so this one is a little heads-up bestie ๐ If gfortran spots a procedure named like an intrinsic that isn't available in the standard you picked (with-std), it warns you and treats that procedure as anEXTERNALprocedure. If you never want that to happen and always want the intrinsic linked no matter which standard you chose,-fall-intrinsicsis the move โจ-Wno-overwrite-recursiveโ no warning when you use-fno-automaticwith-frecursive๐ Recursion gets broken if the relevant local variables don't have theAUTOMATICattribute explicitly declared. Use this to silence the warning when you already know recursion isn't broken. It's super useful for build setups that use-Werror๐ซถ-Wreal-q-constantโ get a warning if a real literal constant has aqexponent letter ๐ธ-Wsurprisingโ this one catches "suspicious" code ๐ It's technically legal, but these constructs usually mean you made a mistake somewhere. Right now it warns in these situations:- An
INTEGER SELECTconstruct has aCASEthat can never be matched, because its lower value is greater than its upper value. - A
LOGICAL SELECTconstruct has threeCASEstatements. - A
TRANSFERhas a source that is 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, not just a warning ๐ - A
CHARACTERvariable is declared with a negative length.
- An
-Wtabsโ tabs are accepted as whitespace by default, but tabs are NOT members of the Fortran Character Set, so be careful ๐ For continuation lines, a tab followed by a digit between 1 and 9 is supported. With-Wtabs, you'll get a warning whenever a tab shows up. It's active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall๐-Wundefined-do-loopโ warns if aDOloop with a step of either1or-1underflows or overflows while the induction variable is iterating ๐ This one is implied by-Wall.-Wunderflowโ warns when numerical constant expressions are encountered that UNDERFLOW during compilation โญ It's enabled by default, so you get it for free.-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 anEXTERNALorINTRINSICdeclaration, so later calls get resolved to the procedure you actually meant. This one is implied by-Wall.-Wuse-without-onlyโ warns if aUSEstatement has noONLYqualifier, because then it quietly imports every public entity of the used module ๐ง-Wunused-dummy-argumentโ warns about unused dummy arguments. Implied by-Wall๐-Wunused-parameterโ okay, plot twist: this is NOT the same as gcc's version ๐ญ gfortran's version doesn't warn about unused dummy arguments (check-Wunused-dummy-argumentfor that). Instead it warns about unusedPARAMETERvalues.-Wunused-parameteris implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commonsโ by default, gfortran warns about any time variables get padded for proper alignment inside aCOMMONblock ๐งธ You can turn that off with-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationโ warns if any calls to impure functions get eliminated by the optimizations turned on by-ffrontend-optimizeโจ This one is implied by-Wextra.-Wrealloc-lhsโ warns when the compiler might insert code for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments ๐ฅ In hot loops, the Fortran 2003 reallocation feature may hurt performance. If the array is already allocated with the right shape, consider using a whole-array array-spec (e.g.(:,:,:)) for the variable on the left-hand side to skip the reallocation check. Heads up: sometimes this warning shows up even when the compiler would optimize those reallocation checks away, like when the right-hand side contains the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allโ warns when the compiler inserts code for allocation or reallocation of an allocatable variable. This includes scalars and derived types too ๐-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 when the compiler can't prove the statement actually runs ๐ฌ Like in this case:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
This one is implied by -Wextra.
-Werrorโ turns ALL warnings into errors ๐จ
Some of these have no effect when compiling programs written in Fortran.
๐ฎ Options for debugging your program or GNU Fortran
GNU Fortran has a bunch of special options for debugging, either your program or the GNU Fortran compiler itself ๐ ๏ธ
-fdump-fortran-originalโ outputs the internal parse tree after the source program gets translated into internal representation ๐ธ This one is mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and it may also generate internal compiler errors for features that were only recently added.-fdump-fortran-optimizedโ outputs the parse tree after front-end optimization ๐ Mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and it may also cause internal compiler errors for features that were only recently 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, and the output might change between releases. It may also generate internal compiler errors for features that were only recently added. > This one is deprecated, so use-fdump-fortran-originalinstead ๐ญ-fdebug-aux-varsโ renames the internal variables the gfortran front end creates and makes them accessible to a debugger ๐ Their names start with upper-case letters followed by an underscore. This is handy for debugging the compiler's code generation alongside-fdump-tree-original, and for debugging the executable by using-gor-ggdb3.-fdump-fortran-globalโ outputs a list of the global identifiers after translating into middle-end representation ๐ง Mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and it may also generate internal compiler errors for features that were only recently added.-ffpe-trap=listโ specifies a list of floating point exception traps to enable ๐ฅ On most systems, if a floating point exception happens and its trap is enabled, aSIGFPEsignal gets sent and the program aborts, producing a core file that's useful for debugging.listis a (possibly empty) comma-separated list of these exceptions: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 correspond to the five IEEE 754 exceptions. The last one, denormal, isn't part of IEEE 754, but it's available on some common architectures such as x86 ๐ฅ๏ธ
The first three (invalid, zero, and overflow) often point to serious errors. Unless your program has ways of dealing with them, enabling traps for these three is probably a good idea ๐ซถ
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.
Once an exception is enabled, it can't be disabled. There's no negative form!
Lots of floating point operations lose 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โ specifies a list of floating-point exceptions whose flag status gets printed toERROR_UNITwhenSTOPandERROR STOPare invoked ๐listcan benone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (Check-ffpe-trapfor descriptions of the exceptions.)
If the option is used more than once on the command line, only the last one is used.
By default, a summary for all exceptions except inexact is shown.
-fno-backtraceโ when a serious runtime error or a deadly signal happens (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals whose action is core), the Fortran runtime library tries to output a backtrace of the error ๐ชฆ-fno-backtraceturns the backtrace generation off. This option only has an effect when compiling the Fortran main program.
๐๏ธ Options for directory search
These options change how GNU Fortran looks for files specified by the INCLUDE directive, and where it looks for previously compiled modules ๐
They also affect the search paths that cpp uses when it preprocesses Fortran source.
-Idirโ these affect how theINCLUDEdirective gets interpreted (and the#includedirective of the cpp preprocessor too) ๐ฆ
okay bestie, the way -I and "INCLUDE" work is basically the same as -I with "#include" in the cpp preprocessor ๐ธ when it comes to hunting down header.gcc files and other stuff like that. no cap, it's giving consistency โจ
This path is also used to search for .mod files when previously compiled modules are required by a "USE" statement ๐
-Jdirโ this one tells the compiler where to drop the .mod files for the modules it compiles ๐ it also gets added to the list of directories a "USE" statement searches ๐
The default is the current directory.
-fintrinsic-modules-path dirโ point this at the pre-compiled intrinsic modules if they're chilling somewhere other than the default spot the compiler 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 totally meaningless, so don't stress ๐
-static-libgfortranโ on systems that have libgfortran as both a shared and a static library, this forces the static version ๐ if no shared version got built when the compiler was configured, this option does absolutely nothing ๐
๐ Influencing runtime behavior ๐
these options change how programs compiled with GNU Fortran behave at runtime โจ
-fconvert=conversionโ this sets how data is represented in unformatted files ๐ฆ the valid values for conversion are:nativeโ the default, no cap ๐swapโ swaps between big- and little-endian ๐big-endianโ uses big-endian representation for unformatted fileslittle-endianโ uses little-endian representation for unformatted files
โ ๏ธ this one only has an effect when it's used in the main program. The "CONVERT" specifier and theGFORTRAN_CONVERT_UNITenvironment variable both override whatever default you set with-fconvert, so they basically get the final say ๐
-frecord-marker=lengthโ sets the length of record markers for unformatted files ๐ valid values for length are4and8, and the default is4. this is different from older gfortran versions, which defaulted to a record marker length of8on most systems ๐ if you want to read or write files that are compatible with earlier gfortran versions, use-frecord-marker=8.-fmax-subrecord-length=lengthโ sets the maximum length for a subrecord ๐ the max permitted value for length is2147483639, which is also the default. honestly it's only really useful for the gfortran testsuite, so unless you're in that world, you can skip it ๐งช-fsign-zeroโ when this is enabled, floating point numbers with a value of zero but the sign bit set get written as negative numbers in formatted output, and they're treated as negative in the "SIGN" intrinsic ๐-fno-sign-zerogoes the other way: it doesn't print the negative sign of zero values (or values rounded to zero for I/O), and it counts zero as a positive number in the "SIGN" intrinsic, which is for compatibility with Fortran 77 ๐ฆ the default is-fsign-zero.
๐ Options for code generation conventions ๐
these machine-independent options control the interface conventions used in code generation ๐ง
most of them have both positive and negative forms, and the negative form of -ffoo is -fno-foo ๐ in the table below, only one of the forms is listed, the one that isn't 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 as RECURSIVE) as if the "SAVE" statement were specified for every local variable and array referenced in it ๐พ it doesn't affect common blocks. (some Fortran compilers give this option 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. if you want no static memory at all, use the option-frecursive๐ธ
Local variables or arrays that have an explicit "SAVE" attribute are silently ignored unless the -pedantic option is added.
-ff2cโ generates code designed to be compatible with code generated by g77 and f2c ๐ซถ
the calling conventions used by g77 (originally implemented in f2c) require functions that return type default "REAL" to actually return the C type "double", and functions that return type "COMPLEX" to return their values via an extra argument in the calling sequence that points to where the return value should be stored ๐ญ under the default GNU calling conventions, those functions just return their results the way GNU C does: default "REAL" functions return the C type "float", and "COMPLEX" functions return the GNU C type "complex" โจ on top of that, this option implies the -fsecond-underscore option, unless -fno-second-underscore is explicitly requested.
This does not affect the generation of code that interfaces with the libgfortran library.
โ ๏ธ Caution: it is not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions. calling "COMPLEX" or default "REAL" functions between program parts that were compiled with different calling conventions will break at execution time ๐
โ ๏ธ Caution: this will break code that passes intrinsic functions of type default "REAL" or "COMPLEX" as actual arguments, because the library implementations use the -fno-f2c calling conventions ๐ญ
-fno-underscoringโ do not transform 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 with no underscores. this is done to ensure compatibility with code produced by many UNIX Fortran compilers ๐
โ ๏ธ Caution: the default behavior of GNU Fortran is incompatible with f2c and g77, so please use the -ff2c option if you want object files compiled with GNU Fortran to be compatible with object code created with these tools.
use of -fno-underscoring is not recommended unless you're experimenting with things like integrating GNU Fortran into existing system environments (vis-ร -vis existing libraries, tools, and so on) ๐งช
for example, with -funderscoring, and assuming that j() and max_count() are external functions while "my_var" and "lvar" are local variables, a statement like
I = J() + MAX_COUNT (MY_VAR, LVAR)
is implemented as something akin to:
i = j_() + max_count__(&my_var__, &lvar);
With -fno-underscoring, the same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
use of -fno-underscoring allows direct specification of user-defined names while debugging and when interfacing GNU Fortran code with other languages ๐ซถ
note that just because the names match doesn't mean the interface implemented by GNU Fortran for an external name matches the interface implemented by some other language for that same name ๐ค getting code produced by GNU Fortran to link to code produced by some other compiler using this or any other method can be only a small part of the overall solution. getting the code generated by both compilers to agree on issues other than naming can require significant effort, and unlike naming disagreements, linkers normally cannot detect disagreements in these other areas.
also, note that with -fno-underscoring, the lack of appended underscores introduces the very real possibility that a user-defined external name will conflict with a name in a system library ๐ฑ this could make finding unresolved-reference bugs quite difficult in some cases, since they might occur at program run time and only show up as buggy behavior at run time.
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 it's implied by use of the -ff2c option ๐ฆ
-fcoarray=<keyword>โ controls coarray support ๐ the keyword can be:noneโ disables coarray support. using coarray declarations and image-control statements will produce a compile-time error ๐ซ (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>โ enables the generation of run-time checks ๐ the argument should be a comma-delimited list of the following keywords. 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 in 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 it makes sure 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โ enables generation of run-time checks for invalid modification of loop iteration variables ๐
memโ ๐ง okay so this one turns on run-time checks for memory allocation. Heads up, bestie: it does not touch explicit allocations made with theALLOCATEstatement. Those are always checked, no exceptions ๐pointerโ ๐ฆ checks pointers and allocatables at run timerecursionโ ๐ checks for subroutines and functions that get called recursively but aren't marked asRECURSIVE. See also-frecursive. โ ๏ธ This check doesn't work for OpenMP programs, and it gets switched off if you use it together with-frecursiveand-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 โจ
-fbounds-checkโ ๐ซถ a deprecated alias for-fcheck=bounds, so it still works but it's on its way out-ftail-call-workaround,-ftail-call-workaround=nโ ๐ง okay this one is a whole saga. Some C interfaces to Fortran code violate the gfortran ABI by leaving out the hidden character length arguments as described in. This can lead to crashes, because pushing arguments for tail calls can overflow the stack ๐ญ
To help out existing binary packages, this option turns off tail call optimization for gfortran procedures with character arguments. With -ftail-call-workaround=2, tail call optimization is disabled in all gfortran procedures with character arguments. With -ftail-call-workaround=1 or equivalent -ftail-call-workaround, it's only disabled 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 generate prototypes that conform to gfortran's ABI, which you can include in your source code ๐ธ
๐ Support for this option will likely be withdrawn in a future release of gfortran.
The negative form, -fno-tail-call-workaround or equivalent -ftail-call-workaround=0, can be used to disable this option.
Default is currently -ftail-call-workaround. This will change in future releases.
-fcheck-array-temporariesโ ๐ a deprecated alias for-fcheck=array-temps-fmax-array-constructor=nโ ๐ raises the upper limit allowed in array constructors. The code below needs this option to expand the array at compile time:
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
๐จ Caution: This option can lead to long compile times and excessively large object files.
The default value for n is 65535.
-fmax-stack-var-size=nโ ๐ sets the size in bytes of the largest array that gets put on the stack. If the size is exceeded, static memory is used instead (except in procedures marked asRECURSIVE). Use-frecursiveto allow 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โ ๐ฅ stacks up every array 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โ ๐ฆ tells GNU Fortran to pack derived type members as closely as possible. Code compiled with this option is likely to be incompatible with code compiled without it, and it may execute slower ๐ข-frepack-arraysโ ๐ช sometimes GNU Fortran passes assumed shape array sections via a descriptor that describes a noncontiguous area of memory. This option adds code to the function prologue that repacks the data into a contiguous block at runtime.
This should make array accesses faster. However, it can add 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-fshort-enums. It makes GNU Fortran choose the smallestINTEGERkind that a given enumerator set will fit in, and gives all its enumerators that kind.-finline-arg-packingโ ๐ when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit-size argument, or to a procedure without an explicit interface, the argument may need to be packed (put into contiguous memory). An example is the call tofooin:
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, this packing is done by inline code. That allows more optimization, but the code size goes up ๐
-finline-arg-packing is implied by any of the -O options, except when optimizing for size via -Os. If the code has a very large number of arguments that need packing, the code size and compilation time may get excessive. In that case, it may be better to disable this option. You can find instances of packing by using -Warray-temporaries.
-fexternal-blasโ ๐งฎ makes gfortran call BLAS functions for some matrix operations likeMATMUL, instead of using its own algorithms, if the matrices involved are bigger 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 ๐-fblas-matmul-limit=nโ ๐ฏ only matters when-fexternal-blasis in effect. Matrix multiplication of matrices with a size larger than (or equal to)ngets done by calls to BLAS functions, while smaller ones are handled by gfortran's internal algorithms. If the matrices 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-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, because code for both cases is generated. Setting-finline-matmul-limit=0disables inlining in all cases. Setting this option with a value ofnproduces inline code for matrices with a size up ton. If the matrices 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 option 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,-finit-derived,-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>,-finit-logical=<true|false>,-finit-character=nโ ๐ฑ the init crew!-finit-local-zerotells the compiler to initialize localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes. The finer-grained options are-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).
With -finit-derived, components of derived type variables get initialized according to these flags. Components whose type isn't covered by an explicit -finit-* flag get treated the way they are with -finit-local-zero, as described above.
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.)
Note that -finit-real=nan initializes REAL and COMPLEX variables with a quiet NaN. For a signalling NaN, use -finit-real=snan. Heads up though: compile-time optimizations may convert them into a quiet NaN, and trapping needs to be enabled (e.g. via -ffpe-trap) ๐ง
The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. That value is then assigned to the integer variables in the Fortran code, which might wrap around if the value is too large for the kind ๐
Finally, enabling any of the -finit-* options will silence warnings that -Wuninitialized would have emitted for the affected local variables ๐คซ
-falign-commonsโ ๐ by default, gfortran enforces proper alignment of all variables in aCOMMONblock by padding them as needed. On certain platforms this is mandatory, and on others it boosts performance. If aCOMMONblock isn't declared with consistent data types everywhere, this padding can cause trouble, so-fno-align-commonscan be used to disable 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โ okay so by default, parentheses in an expression are honored at every optimization level, which means the compiler is not allowed to do any re-association ๐ โโ๏ธ. Using-fno-protect-parenslets the compiler reorderREALandCOMPLEXexpressions to get faster code โก. Heads up, bestie: for that re-association 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 gets automatically (re)allocated if it's either unallocated or has a different shape ๐ฆ. This is on by default except when-std=f95is given. Also check out-Wrealloc-lhs๐ธ.-faggressive-function-eliminationโ functions with identical argument lists get eliminated within statements, whether or not they're markedPURE๐. 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 one does front-end optimization by messing with parts of the Fortran parse tree ๐ง. It's on by default with any-Ooption except-O0and-Og๐. The optimizations it turns on 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)), and - short-circuiting of logical operators (
.AND.and.OR.).
- inlining calls to
You can deselect it with -fno-frontend-optimize ๐.
-ffrontend-loop-interchangeโ this tries to swap loops around in the Fortran front end when it's worth it ๐. It's on by default with any-Ooption ๐. Right now it only affectsFORALLandDO CONCURRENTstatements that have several forall triplets ๐.
โจ ENVIRONMENT โจ
okay so gfortran doesn't use any environment variables to control how it runs, beyond the ones that already affect gcc ๐ธ. Main character energy, but make it minimal ๐ .
๐ BUGS ๐
If you find a bug and want to report it, the instructions live in <file:///usr/share/doc/gcc-11/README.Bugs> ๐. Go read it, bestie ๐ซถ.
๐ฆ SEE ALSO ๐ฆ
Here's the squad of related pages and docs ๐: gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), and dbx(1). You can also check the Info entries for gcc, cpp, gfortran, as, ld, binutils, and gdb ๐โจ.
๐ AUTHOR ๐
For the contributors to GCC and GNU Fortran, look up the Info entry for gfortran ๐. They're the real MVPs ๐.
โญ COPYRIGHT โญ
Copyright (c) 2004-2021 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 ๐. 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. ๐
That's the whole page, bestie! ๐ It's the GFORTRAN(1) manual from the gcc-11 docs, last updated 2024-07-19, and you're officially a gfortran expert now ๐ โจ periodt ๐ฆ๐
๐ฆ where this page comes from
- ubuntu questing: gfortran-11-hppa-linux-gnu 11.5.0-7ubuntu1cross1
- ubuntu resolute: gfortran-11-hppa-linux-gnu 11.5.0-11ubuntu2cross1
- ubuntu stonking: gfortran-11-hppa-linux-gnu 11.5.0-11ubuntu2cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms