GFORTRAN(1)
๐ GFORTRAN(1) โ the GNU Fortran compiler ๐
Okay bestie, this is the manual page for GFORTRAN(1), and it's giving full compiler-nerd energy ๐ค๐ Let's go through it together!
โจ NAME โจ
Okay so the NAME part is short and sweet: gfortran is the GNU Fortran compiler ๐
๐ SYNOPSIS ๐
The basic shape of the command is this ๐
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 here, so don't panic if you don't see everything. The rest is further down the page ๐ฆ
๐ธ DESCRIPTION ๐ธ
The gfortran command is literally iconic because it supports all the options that gcc supports ๐ This page only documents the stuff that's specific to GNU Fortran, so you're not getting a repeat of the GCC basics here.
All GCC and GNU Fortran options work with both gfortran and gcc, along with any other drivers built at the same time (like g++). The reason is that once GNU Fortran is part of the GCC distribution, all the relevant drivers accept GNU Fortran options. Main character energy ๐
Some options come in a positive and a negative form. For example, the negative form of -ffoo is -fno-foo. This manual only documents one of the two, whichever one isn't the default โจ
๐ OPTIONS ๐
Here's the vibe check on every option specific to GNU Fortran, grouped by type. The actual explanations come after the summary, so keep scrolling ๐
๐ Quick summary
๐ 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
-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
These options control the details of the Fortran dialect that the compiler accepts ๐
-ffree-form,-ffixed-formโ These pick the layout of your source file. Free form arrived with Fortran 90, while fixed form is what the older Fortran programs were written in. If you don't specify either one, the source form gets figured out from the file extension โจ-fall-intrinsicsโ This makes every intrinsic procedure work, including the GNU-specific extensions ๐ It's super useful alongside-std=f95if you want standard compliance but still want the full range of intrinsicsgfortranoffers. The catch is that-Wintrinsics-stdgets ignored, and no user-defined procedure with the same name as 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 definition or between different calls. That code is non-conforming and usually gets flagged with an error. This option downgrades that error to a warning, which you can only turn off by disabling all warnings with-w. Only a single occurrence per argument gets flagged. This is implied by-std=legacy๐
Using this option is strongly discouraged! You can write standard-conforming code that allows different types of arguments by using an explicit interface and TYPE(*).
-fallow-invalid-bozโ A BOZ literal constant can only show up in a limited number of contexts in standard conforming Fortran. This option downgrades that error to a warning and lets a BOZ literal constant appear where the Fortran standard would otherwise 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, 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 is DEC compatibility mode ๐ฐ๏ธ It turns on extensions and other features that copy the default behavior of older compilers (like DEC's). These features are non-standard, so you should avoid them at all costs! For the details on how GNU Fortran implements these extensions, check the full documentation. The other flags this switch turns on are-fdollar-ok,-fcray-pointer,-fdec-char-conversions,-fdec-structure,-fdec-intrinsic-ints,-fdec-static,-fdec-math,-fdec-include,-fdec-blank-format-item, and-fdec-format-defaults. If-fd-lines-as-code/-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 (on top of%). It's only here for compatibility though, so Fortran 90 derived types are the better choice wherever you can use them ๐ธ-fdec-intrinsic-intsโ This turns on the B/I/J/K kind variants of existing integer functions (e.g.BIAND,IIAND,JIAND, etc...). For the complete list of intrinsics, peep the full documentation ๐-fdec-mathโ This enables legacy math intrinsics likeCOTANand the degree-valued trig functions (e.g.TAND,ATAND, etc...), so older code keeps working for compatibility ๐งฎ-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 the usualINCLUDEline. 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 you use the format specifiersF,G, andIwithout width specifiers. The default widths get used instead ๐-fdec-blank-format-itemโ This enables a blank format item at the end of a format specification, i.e. nothing following the final comma ๐-fdollar-okโ This allows$as a valid non-first character in a symbol name. Symbols that start with$get 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, switching from a single backslash character to "C-style" escape characters ๐ The combinations\a,\b,\f,\n,\r,\t,\v,\\, and\0expand to the ASCII alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL characters, in that order. On top of that, the\xescape followed bynn, the\uescape followed bynnnn, and the\Uescape followed bynnnnnnnn(where eachnis a hexadecimal digit) get translated into the Unicode characters for those code points. Every other combination 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 are ignored in typical fixed-form lines in the source file. Unless-fno-pad-sourceis used, spaces are also assumed (as if padded to that length) after the ends of short fixed-form lines ๐ Popular values fornare 72 (the standard and the default), 80 (card image), and 132 (corresponding to "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-0means the 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 padding 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 have implicit spaces appended to fill out the line ๐ซถ-ffree-line-length-nโ okay so this one sets the column where the compiler stops caring ๐. In typical free-form source files, anything past columnngets ignored. The default is132โจ. You can passnoneas thenvalue so the entire line counts ๐.-ffree-line-length-0does the exact same thing as-ffree-line-length-none.-fmax-identifier-length=nโ sets the longest identifier you're allowed to use ๐งธ. Typical values are31(Fortran 95) and63(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 start of every procedure ๐ .-fcray-pointerโ turns on the Cray pointer extension, which gives you C-like pointer vibes ๐ง.-fopenaccโ enables the OpenACC extensions ๐. That includes!$accdirectives in free form, plusc$acc,*$accand!$accdirectives in fixed form. It also turns on the!$conditional compilation sentinels in free form and thec$,*$and!$sentinels in fixed form. When you link, it makes sure the OpenACC runtime library gets linked in too ๐.-fopenmpโ enables the OpenMP extensions ๐ฅ. That covers!$ompdirectives in free form,c$omp,*$ompand!$ompdirectives in fixed form, and the same!$,c$,*$and!$sentinels as above. Linking also arranges for the OpenMP runtime library to be linked in. Heads up, bestie:-fopenmpimplies-frecursive๐ซถ.-fno-range-checkโ disables range checking on the results of simplifying constant expressions during compilation ๐. Normally GNU Fortran throws a compile-time error for something likea = 1. / 0. With this flag there's no error, andagets the value+Infinity๐. If an expression lands outside the relevant range of["-HUGE()":HUGE()], it gets replaced by-Infor+Inf, whichever fits. Also,DATA i/Z'FFFFFFFF'/would overflow on most systems, but with this flag the value wraps around andiends up as-1๐.-fdefault-integer-8โ sets the default integer and logical types to an 8 byte wide type ๐. It also changes the kind of integer constants like42. Unlike-finteger-4-integer-8, it won't promote variables that have 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-10and-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 needs care and may not suit your codebase.
โ ๏ธ Be careful with this one, bestie! Possible trouble spots include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. It's suggested that you inspect the intermediate representation of the translated Fortran code, produced by-fdump-tree-original๐ซฃ.
-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 all promote everyREAL(KIND=M)entity toREAL(KIND=N)๐ช. IfREAL(KIND=N)isn't available, you'll get an error. Every other real kind type is unaffected. Same deal as before: use with care, since these may not suit your code. The areas of concern are the same too: external procedure calls, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. Inspecting the intermediate representation, produced by-fdump-tree-original, is suggested ๐.-std=stdโ picks the standard your program is expected to follow ๐. The options aref95,f2003,f2008,f2018,gnu, orlegacy. The default isgnu, which is 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 in new code.legacyis the same, but without those obsolete-extension warnings, which makes it handy for old non-standard programs ๐ซ . Thef95,f2003,f2008andf2018values are strict: they conform to Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 respectively. You'll get errors for any extension beyond the chosen standard, and warnings for Fortran 77 features that are still allowed but obsolescent in later standards.
๐ The deprecated-std=f2008tsoption is an alias for-std=f2018. It's only there for backwards compatibility with earlier gfortran versions, so it should not be used any more.
-ftest-forall-tempโ boosts test coverage by forcing mostforallassignments to use a temporary ๐งช.
โจ Enable and customize preprocessing โจ
Preprocessor related options, bestie ๐. For more detail, see the section Preprocessing and conditional compilation for everything about preprocessing in gfortran.
-cpp,-nocppโ-cppenables preprocessing ๐ช. The preprocessor gets invoked automatically if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08. Use this option to manually enable preprocessing for any kind of Fortran file. To turn off preprocessing for files with any of those extensions, use the negative form,-nocpp๐ โโ๏ธ. The preprocessor runs in traditional mode. Any file-format restrictions, especially the limits on line length, also apply to preprocessed output, so it might be a good idea to use-ffree-line-length-noneor-ffixed-line-length-none๐.-dMโ instead of the normal output, this generates a list of#definedirectives for all the macros defined during the preprocessor run, including the predefined ones ๐. It's a great way to find out what's predefined in your version of the preprocessor ๐ฎ. Assuming you have no filefoo.f90, this command:
touch foo.f90; gfortran -cpp -E -dM foo.f90
will show all the predefined macros ๐ธ.
-dDโ like-dM, except it doesn't include the predefined macros. It also 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โ likedD, except only macros that get expanded, or whose definedness is tested in preprocessor directives, are output ๐ฆ. The output is delayed until the macro is used or tested.#undefdirectives are also output for macros that were tested but were undefined at the time.-dIโ outputs#includedirectives in addition to the result of preprocessing ๐.-fworking-directoryโ enables linemarkers in the preprocessor output that tell the compiler the current working directory at the time of preprocessing ๐บ๏ธ. When this is on, the preprocessor emits a second linemarker after the initial one, containing the current working directory followed by two slashes. GCC will use this directory, when it's present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats. This 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 only after all the directories specified with-Iand the standard system directories have been exhausted ๐.diris treated as a system include directory. Ifdirbegins with=, that=gets replaced by the sysroot prefix; see--sysrootand-isysroot๐งญ.-imultilib dirโ usesdiras a subdirectory of the directory containing target-specific C++ headers ๐ฏ.-iprefix prefixโ setsprefixas the prefix for subsequent-iwithprefixoptions ๐ท๏ธ. If the prefix represents a directory, you should include the final/.-isysroot dirโ works like the--sysrootoption, but only applies to header files ๐. See the--sysrootoption for more information.-iquote dirโ searchesdironly for header files requested with#include "file"๐ฌ. They're not searched for#include <file>. This happens before all the directories specified by-Iand before the standard system directories. Ifdirbegins with=, that=gets replaced by the sysroot prefix; see--sysrootand-isysrootโจ.-isystem dirโ okay bestie, this tells the compiler to hunt for header files in dir ๐ It gets searched after every directory you gave with-I, but before the standard system directories. It's also marked as a system directory, so it gets the same VIP treatment as the standard ones ๐ If dir starts with=, that=gets swapped out for the sysroot prefix. Check out--sysrootand-isysrootfor the deets โจ-nostdincโ no more snooping through the standard system directories for headers ๐ โโ๏ธ Only the directories you gave with-Ioptions (plus the directory of the current file, if appropriate) get searched.-undefโ don't predefine any system-specific or GCC-specific macros ๐งผ The standard predefined macros stay put, though.-Apredicate=answerโ make an assertion with the predicate predicate and the answer answer ๐ This is the fave form over the older-A predicate(answer), which still works but isn't as chill. This one doesn't use shell special characters, so it's giving clean vibes ๐-A-predicate=answerโ cancel an assertion with the predicate predicate and the answer answer ๐-Cโ don't toss the comments! All comments get passed through to the output file, except 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โ don't discard comments, even during macro expansion ๐งต It's like-C, except comments inside macros also get passed through to the output file where the macro gets 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 a later use 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โ predefine 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: the definition gets truncated by embedded newline characters.
If you're invoking the preprocessor from a shell or shell-like program, you might need the shell's quoting syntax to protect characters like spaces that have a meaning in shell syntax ๐
Want a function-like macro on the command line? Write its argument list with surrounding parentheses before the equals sign (if any). Parentheses mean stuff to most shells, so you'll 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 -D and -U options ๐
-Hโ print the name of each header file used, along with the other normal stuff ๐ Each name is indented to show how deep it sits in the#includestack ๐ช-Pโ inhibit generation of linemarkers in the preprocessor output ๐ซ This might be useful when you run the preprocessor on something that isn't C code and will be sent to a program that could get confused by the linemarkers ๐ซถ-Unameโ cancel any previous definition of name, whether it was built in or provided with a-Doption ๐๏ธ
๐ฆ Options to request or suppress errors and warnings ๐ฆ
Errors are diagnostic messages saying the GNU Fortran compiler can't compile the relevant piece of source code ๐ญ The compiler keeps processing the program to report further errors and help you debug, but it won't produce any compiled output.
Warnings are diagnostic messages about constructions that aren't inherently erroneous but are risky or suggest there's likely a bug in the program ๐ Unless -Werror is specified, they don't prevent the program from compiling.
You can request lots of specific warnings with options beginning -W, like -Wimplicit to request warnings on implicit declarations ๐ Each of these specific warning options also has a negative form beginning -Wno- to turn warnings off, like -Wno-implicit. This manual only lists one of the two forms, whichever one is not the default ๐ค
These options control the amount and kinds of errors and warnings GNU Fortran produces:
-fmax-errors=nโ caps the number of error messages at n, and then GNU Fortran bails instead of trying to keep going ๐ 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 ๐ It'll generate module files for each module present in the code, but no other output file.-Wpedantic,-pedanticโ issue warnings for uses of extensions to Fortran ๐ง-pedanticalso applies to C-language constructs where they occur in GNU Fortran source files, like use of\ein a character constant within a directive like"#include".
Valid Fortran programs should compile properly with or without this option ๐ซถ Without it, though, certain GNU extensions and traditional Fortran features are supported too. With this option, lots of them get rejected.
Some users try to use -pedantic to check programs for conformance. They soon find it doesn't do quite what they want, since it finds some nonstandard practices but not all ๐ฉ Still, improvements to GNU Fortran in this area are welcome ๐
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018.
-pedantic-errorsโ like-pedantic, except errors get produced instead of warnings ๐-Wallโ enables commonly used warning options for usage 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: With no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that initiated the continuation. ๐ง
-Warray-temporariesโ warns about array temporaries generated by the compiler ๐ The information from this warning is sometimes useful in optimization, in order to avoid such temporaries.-Wc-binding-typeโ warns if a variable might not be C interoperable ๐ In particular, it warns if the variable has been declared using an intrinsic type with default kind instead of 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 error ๐ฑ-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-interchangefor performing loop interchanges ๐-Wimplicit-interfaceโ warns if a procedure is called without an explicit interface ๐ซฃ Note this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units.-Wimplicit-procedureโ warns if a procedure is called that has neither an explicit interface nor has been declared as"EXTERNAL"๐ฃ-Winteger-divisionโ warns if a constant integer division truncates its result ๐ For example,3/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 this ๐ต๏ธ-fall-intrinsicscan be used to never trigger this behavior and always link to the intrinsic regardless of the selected standard.-Wno-overwrite-recursiveโ don't warn when-fno-automaticis used with-frecursive๐ Recursion will be broken if the relevant local variables don't have the attribute"AUTOMATIC"explicitly declared. This option can be used to suppress the warning when it's known that recursion is not broken. Useful for build environments that use-Werror๐ ๏ธ-Wreal-q-constantโ produces a warning if a real-literal-constant contains a"q"exponent-letter ๐-Wsurprising: ๐ Heads up, bestie! This flags "suspicious" code constructs. They're technically legal, but they usually mean someone messed up, so lowkey double-check. It currently 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
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 on, this is an error ๐. - A
CHARACTERvariable is declared with a negative length.
- An
-Wtabs: ๐ Tabs are accepted as whitespace by default, but they're not part of the Fortran Character Set, so they're kinda sus. For continuation lines, a tab followed by a digit from 1 to 9 is supported. Turn this on and you'll get a warning every time a tab shows up. Also,-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall.-Wundefined-do-loop: Warns if aDOloop with step either1or-1hits an underflow or an overflow while its induction variable is iterating. Implied by-Wall.-Wunderflow: Warns when numerical constant expressions yield anUNDERFLOWduring 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 anEXTERNALorINTRINSICdeclaration so your calls resolve to the procedure you actually wanted ๐ฏ. Implied by-Wall.-Wuse-without-only: Warns if aUSEstatement has noONLYqualifier, which means it quietly imports every public entity of the module.-Wunused-dummy-argument: Warns about unused dummy arguments. Implied by-Wall.-Wunused-parameter: Plot twist ๐! Unlike gcc, gfortran's version does not warn about unused dummy arguments (for that, see-Wunused-dummy-argument). It warns about unusedPARAMETERvalues instead. Implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commons: By default, gfortran warns whenever variables get padded for 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 enabled by-ffrontend-optimize. Implied by-Wextra.-Wrealloc-lhs: Warns when the compiler might insert allocation or reallocation code for 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 correct shape, use a whole-array array-spec (e.g.(:,:,:)) on the left-hand side to skip the reallocation check. Note that sometimes this warning shows up even when the compiler would optimize the checks away anyway, like when the right-hand side has the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-all: Warns when the compiler inserts allocation or reallocation code for an allocatable variable. This includes scalars and derived types.-Wcompare-reals: Warns when real or complex types get compared 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 at compile time to execute zero times. 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. Here's the kind of situation it's talking about ๐ง:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
This option is implied by -Wextra.
-Werror: Turns all warnings into errors. ๐
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. 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 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 generate internal compiler errors for features that were only recently added.-fdump-parse-tree: Outputs the internal parse tree after the source program gets translated into internal 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. This option is deprecated, so use-fdump-fortran-originalinstead โ ๏ธ.-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: Enables a list of floating point exception traps. On most systems, if a floating point exception happens and its trap is enabled, aSIGFPEsignal gets sent and the program is aborted, 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 zero)overflow(overflow in a floating point operation)underflow(underflow in a floating point operation)inexact(loss of precision during an operation)denormal(an operation performed on a denormal value)
The first five match the five IEEE 754 exceptions. The last one, denormal, isn't part of IEEE 754, but it's available on some common architectures, like x86.
The first three exceptions (invalid, zero, and overflow) often point to serious errors. Unless your program has a plan for handling them, enabling traps for those three is probably a good idea ๐.
If the option is used more than once on the command line, the lists get joined. So -ffpe-trap=list1 plus -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, so choose wisely ๐ง .
Lots of floating point operations lose precision due to rounding, so -ffpe-trap=inexact is likely to be 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_UNITwhenSTOPorERROR STOPis invoked ๐.listcan benone,all, or a comma-separated list ofinvalid,zero,overflow,underflow,inexactanddenormal. (See-ffpe-trapfor what each exception means.)
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 shows up (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals whose action is core), the Fortran runtime library tries to print a backtrace of the error.-fno-backtraceturns backtrace generation off. It only has an effect when compiling the Fortran main program.
โจ Options for directory search โจ
These options affect how GNU Fortran searches for files specified by the INCLUDE directive, and where it searches for previously compiled modules ๐๏ธ.
They also affect the search paths used by cpp when it preprocesses Fortran source.
-Idir: These affect how theINCLUDEdirective gets interpreted, as well as the#includedirective of the cpp preprocessor. The general behavior of-IandINCLUDEis pretty much the same as-Iwith#includein cpp, when it comes to looking forheader.gccfiles and other such things ๐. This path is also used to search for.modfiles when previously compiled modules are required by aUSEstatement.-Jdir: Specifies where to put.modfiles for compiled modules. It also gets added to the list of directories searched by aUSEstatement. The default is the current directory ๐.-fintrinsic-modules-path dir: Specifies the location of pre-compiled intrinsic modules, if they aren't in the default location the compiler expects.
โจ Influencing the linking step โจ
These options come into play when the compiler links object files into an executable output file ๐. They're meaningless if the compiler isn't doing a link step.
-static-libgfortran: On systems that provide libgfortran as both a shared and a static library, this forces the use of the static version. If no shared version of libgfortran was built when the compiler was configured, this option has no effect ๐คท.
โจ Influencing runtime behavior โจ
These options affect the runtime behavior of programs compiled with GNU Fortran ๐โโ๏ธ๐.
-fconvert=conversionโ okay so this one decides how data gets represented in unformatted files ๐ The valid values forconversionarenative(the default ๐ธ),swap(flips between big- and little-endian ๐),big-endian(uses big-endian representation for unformatted files), andlittle-endian(uses little-endian representation for unformatted files).
This only has an effect when it's used in the main program ๐. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable both override the default set by -fconvert โจ.
-frecord-marker=lengthโ this sets the length of record markers for unformatted files ๐ฆ. The valid values forlengthare4and8, and the default is4. Be warned that this is different from older versions of gfortran, which defaulted to a record marker length of8on most systems ๐. If you need 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 biggest allowed value forlengthis2147483639, which is also the default ๐. It's only really useful for the gfortran testsuite, so don't stress about it ๐ง.-fsign-zeroโ when this is enabled, zero-valued floats with the sign bit set get written as negative numbers in formatted output, and they're treated as negative by theSIGNintrinsic โ.-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 treats zero as positive in theSIGNintrinsic ๐. That's 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 ๐ฆ. Below, only one of the forms is listed (the one that is not the default), so you can figure out the other by removing no- or adding it ๐.
-fno-automaticโ treats each program unit (except the ones marked asRECURSIVE) as if theSAVEstatement were specified for every local variable and array in it ๐. It doesn't affect common blocks. (Some Fortran compilers give this option the name-staticor-save๐ธ.) The default,-fautomatic, uses the stack for local variables that are smaller than the value given by-fmax-stack-var-size๐ฅ. If you want to use no static memory at all, use the option-frecursive๐.
Local variables or arrays with an explicit SAVE attribute are silently ignored, unless the -pedantic option is added ๐.
-ff2cโ generates code that's compatible with code generated by g77 and f2c ๐ค.
The calling conventions used by g77 (originally from f2c) require functions that return default REAL to actually return the C type double, and functions that return type COMPLEX to return their values through an extra argument in the calling sequence. That extra argument points to where the return value gets stored ๐. Under the default GNU calling conventions, these functions just return their results like they would in GNU C: default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex ๐ง. On top of that, this option implies -fsecond-underscore, unless -fno-second-underscore is explicitly requested โจ.
This doesn't affect the generation of code that interfaces with the libgfortran library.
Caution: mixing Fortran code compiled with-ff2cand code compiled with the default-fno-f2ccalling conventions is a really bad idea ๐. CallingCOMPLEXor defaultREALfunctions between program parts compiled with different calling conventions will break at execution time ๐ญ.
Caution: this will break code that passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments ๐จ, because the library implementations use the-fno-f2ccalling conventions ๐.
-fno-underscoringโ stops GNU Fortran from transforming the names of entities in your Fortran source file by appending underscores to them ๐ โโ๏ธ.
With -funderscoring in effect, GNU Fortran appends one underscore to external names that have no underscores already ๐. This is done so it stays compatible with code produced by many UNIX Fortran compilers ๐ซถ.
Caution: the default behavior of GNU Fortran is incompatible with f2c and g77 ๐. If you want object files compiled with GNU Fortran to be compatible with object code created by those tools, please use the -ff2c option ๐.
Using -fno-underscoring isn't 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 this:
I = J() + MAX_COUNT (MY_VAR, LVAR)
gets implemented as something akin to this:
i = j_() + max_count__(&my_var__, &lvar);
With -fno-underscoring, that same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
Using -fno-underscoring lets you specify user-defined names directly while debugging, and when you're interfacing GNU Fortran code with other languages ๐.
Just because the names match, though, doesn't mean the interface GNU Fortran implements for an external name matches the interface some other language implements for that same name ๐. Getting GNU Fortran code to link with code from another compiler (using this or any other method) can be only a small part of the overall solution ๐งฉ. Getting the code from both compilers to agree on things other than 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 makes it very real that a user-defined external name could conflict with a name in a system library โ ๏ธ. That could make finding unresolved-reference bugs super hard, since they might only happen at run time and show up as buggy behavior ๐.
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 ๐ฎ. This would be true even if the names 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 you use this option, GNU Fortran appends two underscores to names that have underscores in them, and one underscore to external names with no underscores ๐. It also appends two underscores to internal names that have underscores, so they don't collide with external names ๐ซง.
This option has no effect if -fno-underscoring is in effect ๐. It's 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>โ picks how coarray support works, using one of these keywords ๐ง: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 1๏ธโฃ.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 has to be a comma-delimited list of the keywords below. Puttingno-in front of a check disables it, if it was turned on by a previous specification ๐ โโ๏ธ.allโ enables all run-time tests of-fcheck๐.array-tempsโ warns at run time when, to pass an actual argument, a temporary array had to be generated ๐ฃ. The info from this warning is sometimes useful for optimization, since you can use it to avoid those temporaries ๐ก. Note: the warning only gets printed once per location ๐ซถ.bitsโ enables run-time checks for invalid arguments to the bit manipulation intrinsics ๐ข.boundsโ enables run-time checks for array subscripts, 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 that don't have an explicit typespec ๐งต. Some checks require that-fcheck=boundsis set for the compilation of the main program ๐. Note: this may also include other forms of checking in the future, e.g. checking substring references ๐ฎ.doโ enables run-time checks for invalid modification of loop iteration variables ๐.memโ enables run-time checks for memory allocation ๐ง . Note: this option does not affect explicit allocations using theALLOCATEstatement, which are always checked ๐ฏ.pointerโ enables run-time checks for pointers and allocatables ๐.recursionโ enables run-time checks for recursively called subroutines and functions that aren't marked asRECURSIVE๐. See also-frecursive๐ฆ. Note: this check doesn't work for OpenMP programs, and it's disabled if it's used together with-frecursiveand-fopenmp๐.
Example: assuming you have a file foo.f90, the command below
gfortran -fcheck=all,no-array-temps foo.f90
will compile 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๐ โโ๏ธ. Use-fcheck=boundsinstead ๐.-ftail-call-workaround,-ftail-call-workaround=nโ some C interfaces to Fortran code violate the gfortran ABI by omitting the hidden character length arguments, as described in (the original page just trails off right there ๐, so there's no reference to chase down ๐).
Heads up: this can lead to crashes, because pushing arguments for tail calls can overflow the stack ๐จ.
Okay so this is the rest of the -ftail-call-workaround tea ๐ซ. It's a band-aid for existing binary packages ๐ฉน, and it turns off tail call optimization for gfortran procedures with character arguments. -ftail-call-workaround=2 does it in every gfortran procedure with character arguments, while -ftail-call-workaround=1 (or plain -ftail-call-workaround, which is equivalent) only does it 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. Bestie, be careful!
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, so you can include them 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, switches this off ๐ฆ.
Default is currently -ftail-call-workaround, and this will change in future releases.
โจ OPTIONS โจ
-fcheck-array-temporariesโ โ ๏ธ deprecated, but still works as an alias for-fcheck=array-temps๐ฐ๏ธ.-fmax-array-constructor=nโ this is how you raise the upper limit allowed in array constructors ๐. The code below needs it so the array can be expanded 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 can lead to long compile times and excessively large object files ๐. The default value fornis65535.
-fmax-stack-var-size=nโ sets the size in bytes of the biggest array allowed on the stack ๐ฆ. If an array goes over that size, it gets static memory instead (except in procedures markedRECURSIVE) ๐ง. Use-frecursiveif you want recursive procedures that don't have theRECURSIVEattribute, or if you're doing parallel programs ๐งต. Use-fno-automaticif you never want the stack touched ๐ซ. 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, so stay tuned ๐. The default value fornis65536.-fstack-arraysโ puts all arrays of unknown size and array temporaries onto stack memory ๐ฅ. If your program uses very large local arrays, you might have to extend your runtime stack memory limits on some operating systems ๐. This flag is enabled by default at optimization level-Ofast, unless-fmax-stack-var-sizeis specified ๐๏ธ.-fpack-derivedโ tells GNU Fortran to pack derived type members as closely as possible ๐งณ. Code compiled with this is likely to be incompatible with code compiled without it, and it may run slower ๐ข.-frepack-arraysโ sometimes GNU Fortran passes assumed shape array sections through a descriptor that describes a noncontiguous chunk 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 ๐, but it can add a lot of overhead to the function call, especially when the passed data is noncontiguous ๐ตโ๐ซ.-fshort-enumsโ this is 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 dummy, or to a procedure without an explicit interface, the argument may have to be packed (put into contiguous memory) ๐ฆโจ. Here's the classic example, with the call tofooinbar:
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
When -finline-arg-packing is in effect, that packing is done with inline code ๐งโ๐ณ. That allows more optimization, but the code gets bigger ๐. This is implied by any of the -O options, except when you optimize for size with -Os ๐ค. If your code has a very large number of arguments that need packing, the code size and compile time can get out of hand ๐ซ . If that happens, it might be better to disable this option. You can find the instances of packing by using -Warray-temporaries ๐.
-fexternal-blasโ makes gfortran call BLAS functions for some matrix operations, likeMATMUL, instead of its own algorithms ๐งฎ. This only happens if the matrices involved are larger than a given limit (see-fblas-matmul-limit) ๐. This can be a total 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 with matrices of size larger than or equal tonwill go through BLAS calls, and everything smaller gets 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 fornis30.-finline-matmul-limit=nโ when front-end optimization is active, some calls to theMATMULintrinsic function get inlined ๐ช. This can make your code bigger if the matrix size can't be determined at compile time, because 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 up to sizen๐. 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 fornis30, and-fblas-matmul-limitcan be used to change this value ๐.-frecursiveโ allows indirect recursion by forcing all local arrays to be allocated on the stack ๐. This flag cannot be used together with-fmax-stack-var-size=or-fno-automatic๐ซ.-finit-local-zero,-finit-derived,-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>,-finit-logical=<true|false>,-finit-character=nโ the initialization crew ๐ฑ.-finit-local-zerotells the compiler to set localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes ๐ซง. For finer control, there's-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 same way as with -finit-local-zero ๐.
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 those into quiet NaNs, 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 then gets 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 the 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 some platforms this is mandatory, and on others it boosts performance ๐โโ๏ธ. If aCOMMONblock isn't declared with consistent data types everywhere, that padding can cause trouble, and-fno-align-commonscan be used to turn automatic alignment off ๐ . Use the same form of this option for all files that share aCOMMONblock ๐ค. To dodge 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 every optimization level, so the compiler doesn't do any re-association ๐. Using-fno-protect-parenslets the compiler reorderREALandCOMPLEXexpressions to produce faster code ๐๏ธ. For the 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 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 those functions are markedPURE๐๏ธ. For example, ina = f(b,c) + f(b,c), there will only be a single call tofโจ. This option only works if-ffrontend-optimizeis in effect ๐ซถ.-ffrontend-optimizeโ performs front-end optimization, based on manipulating parts of the Fortran parse tree ๐ณ. It's enabled by default by any-Ooption except-O0and-Og๐. Optimizations enabled by this option include:
Okay so the front end does a bunch of cleanup for you, and it's giving efficiency ๐ โจ
- 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.). ๐ฆ
If you ever want it to chill and stop doing all that, just pass -fno-frontend-optimize. Your call, bestie ๐ซถ
โจ -ffrontend-loop-interchange โจ
-ffrontend-loop-interchangeโ this one tries to swap loops around in the Fortran front end when it's actually worth it ๐ It's switched on by default with any-Ooption. Right now it only touchesFORALLandDO CONCURRENTstatements that have several forall triplets, so it's pretty specific, no cap ๐
๐ธ ENVIRONMENT ๐ธ
Honestly, the gfortran compiler doesn't read any environment variables to control how it runs, apart from the ones that already affect gcc. So if you've been hunting for a secret gfortran env var, sorry bestie, it's just gcc vibes ๐
๐ BUGS ๐
Want to report a bug? The instructions are in file:///usr/share/doc/gcc-10/README.Bugs. Go read them and help us squash it ๐ชฒ๐
๐ฆ SEE ALSO ๐ฆ
Here's your reading list, the whole squad ๐
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 ๐
For the contributors to GCC and GNU Fortran, check the Info entry for gfortran. They're the real MVPs ๐ซถ
๐ COPYRIGHT ๐
Copyright (c) 2004-2020 Free Software Foundation, Inc. ๐
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being "Funding Free Software", the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the gfdl(7) man page.
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.
And that's a wrap, bestie! ๐ This whole page was gcc-10 energy, dated 2023-07-07, and it's officially GFORTRAN(1) certified ๐ ๐
๐ฆ where this page comes from
- ubuntu noble: gfortran-10-i686-linux-gnu 10.5.0-4ubuntu2.1cross1
- ubuntu noble: gfortran-10-i686-linux-gnu 10.5.0-4ubuntu2cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms