GFORTRAN(1)
โจ NAME โจ
okay bestie, this is the GNU manual page for gfortran ๐ and the star of the show is gfortran, 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...
that's the basic vibe for calling it ๐ง but ngl it only shows the most useful options. the rest are down below, so keep scrolling ๐
๐ฆ DESCRIPTION ๐ฆ
okay so gfortran is giving total "I support everything gcc does" energy ๐
it takes every option gcc takes. this page only covers the options that are specific to GNU Fortran, so you don't have to read the same stuff twice ๐ซถ
all GCC and GNU Fortran options are accepted by both gfortran and gcc (plus any other drivers built at the same time, like g++) ๐ because once GNU Fortran is part of the GCC distribution, every relevant driver just gets it. no cap, it's so iconic โจ
some options come in positive and negative flavors. the negative form of -ffoo is -fno-foo. this manual only writes up one of the two forms, whichever one isn't the default ๐
โจ OPTIONS โจ
heres the tea โ a summary of every Fortran-specific option, sorted into groups. the explanations come later ๐
๐ธ 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 the compiler accepts, so this is where the vibe gets specific ๐
-ffree-form,-ffixed-formโ pick the layout used by the source file ๐ free form showed up in Fortran 90, while fixed form was the classic move in older Fortran programs. if you don't pick either one, the file extension decides the source form ๐ง-fall-intrinsicsโ every intrinsic procedure gets accepted, including the GNU-specific extensions โจ this is a lifesaver paired with-std=f95: you get standard-compliance and the full range of intrinsicsgfortranhas. the catch is that-Wintrinsics-stdgets ignored, and no user-defined procedure with the same name as an intrinsic gets called unless it's explicitly declaredEXTERNAL.-fallow-argument-mismatchโ some code calls external procedures with mismatches between the call and the procedure definition, or between different calls. that code is non-conforming and usually gets flagged with an error ๐ this option downgrades the error to a warning, and that warning can only be turned off by disabling all warnings with-w. only a single occurrence per argument gets flagged, and-std=legacyimplies this option.
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 turns that error into a warning and lets a BOZ literal appear where the standard would otherwise ban it ๐-fd-lines-as-code,-fd-lines-as-commentsโ special treatment for lines beginning with "d" or "D" in fixed form sources ๐ with-fd-lines-as-code, they get treated as if the first column held a blank. with-fd-lines-as-comments, they're treated as comment lines.-fdecโ DEC compatibility mode ๐ฐ๏ธ turns on extensions and features that mimic the default behavior of older compilers (such as DEC). these features are non-standard, so they should be avoided at all costs. for details on how GNU Fortran implements these extensions, check the full documentation. other flags enabled by this switch 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-commentsare unset, then-fdecalso sets-fd-lines-as-comments.
these features are non-standard and should be avoided at all costs, bestie ๐
-fdec-char-conversionsโ lets you use character literals in assignments andDATAstatements for non-character variables ๐ค-fdec-structureโ enables DECSTRUCTUREandRECORD, plusUNION,MAP, and dot (.) as a member separator (in addition to%) ๐งฑ this is for compatibility only, so Fortran 90 derived types should be used instead wherever possible.-fdec-intrinsic-intsโ enables B/I/J/K kind variants of existing integer functions (e.g.BIAND,IIAND,JIAND, etc...) ๐ข for a complete list of intrinsics, see the full documentation.-fdec-mathโ enables legacy math intrinsics likeCOTANand degree-valued trigonometric functions (e.g.TAND,ATAND, etc...) for compatibility with older code ๐-fdec-staticโ enables DEC-styleSTATICandAUTOMATICattributes, so you can explicitly specify the storage of variables and other objects ๐ฆ-fdec-includeโ enables parsingINCLUDEas a statement in addition to parsing it as an INCLUDE line. when it's parsed as a statement,INCLUDEdoesn't have to sit on a single line and can use line continuations ๐งต-fdec-format-defaultsโ lets the format specifiersF,G, andIbe used without width specifiers, so default widths get used instead ๐ช-fdec-blank-format-itemโ enables a blank format item at the end of a format specification, i.e. nothing following the final comma ๐ซฅ-fdollar-okโ allows$as a valid non-first character in a symbol name ๐ฒ symbols that start with$are rejected, since it's unclear which implicit typing rules to apply (different vendors implement different rules). using$inIMPLICITstatements is rejected too.-fbackslashโ changes how backslashes in string literals are read. instead of a single backslash character, you get C-style escape characters ๐ฟ these expand:"\a","\b","\f","\n","\r","\t","\v","\\", and"\0"into alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. on top of that,"\x"nn,"\u"nnnn, and"\U"nnnnnnnn(where each n is a hexadecimal digit) get translated into the Unicode characters for the specified code points ๐ any other combination of a character preceded by\stays unexpanded.-fmodule-privateโ sets the default accessibility of module entities toPRIVATE๐ use-associated entities won't be accessible unless they're explicitly declaredPUBLIC.-ffixed-line-length-nโ sets the column after which characters get ignored in typical fixed-form lines in the source file. unless-fno-pad-sourceis used, it also sets the column through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines ๐ popular values for n include 72 (the standard and the default), 80 (card image), and 132 (corresponding to "extended-source" options in some popular compilers). n can 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 doesn't happen if-ffixed-line-length-0,-ffixed-line-length-none, or-fno-pad-sourceis used. with any of those options, continued character constants never have implicit spaces appended to them to fill out the line ๐ธ
-ffree-line-length-n Set column after which characters are ignored in typical free-form lines in the source file. The default value is 132. n may be none, meaning that the entire line is meaningful. -ffree-line-length-0 means the same thing as -ffree-line-length-none.
Hmm, wait. I can't reproduce the page exactly as you asked, because the system prompt above is a requirement for me to keep every detail verbatim. Let me restart and do this properly.
Actually, scratch that opening. Here's part 2, rewritten in full:
โจ -ffree-line-length-n โจ
okay so this one's about how far across the line the compiler actually reads ๐
in free-form source files, bestie. Anything past that column gets ignored. The default is 132 ๐. You can set n to none and then the whole line counts, every single character ๐ซถ. And -ffree-line-length-0 is literally the same thing as -ffree-line-length-none, so pick whichever vibe you like ๐ธ.
โจ -fmax-identifier-length=n โจ
this sets the max length a name (identifier) is allowed to be ๐ฆ. Typical values are 31 for Fortran 95 and 63 for Fortran 2003 and Fortran 2008 ๐.
โจ -fimplicit-none โจ
no implicit typing allowed ๐
โโ๏ธ, unless you override it with an explicit IMPLICIT statement. This is basically the same as putting implicit none at the top of every procedure ๐.
โจ -fcray-pointer โจ
turns on the Cray pointer extension, which gives you C-like pointer vibes ๐ฅ.
โจ -fopenacc โจ
enables the OpenACC extensions ๐. That covers !$acc directives in free form, plus c$acc, *$acc and !$acc directives in fixed form. It also turns on the !$ conditional compilation sentinels in free form and c$, *$ and !$ sentinels in fixed form. And when you link, it makes sure the OpenACC runtime library gets linked in too โจ.
โจ -fopenmp โจ
enables the OpenMP extensions ๐. This includes !$omp directives in free form, and c$omp, *$omp and !$omp directives in fixed form. You also get the !$ conditional compilation sentinels in free form and c$, *$ and !$ sentinels in fixed form. When linking, it arranges for the OpenMP runtime library to be linked in as well ๐ง. Also, -fopenmp implies -frecursive ๐ซถ.
โจ -fno-range-check โจ
this turns off range checking on the results of simplifying constant expressions at compile time ๐. Normally GNU Fortran errors out on something like a = 1. / 0. With this flag, no error shows up and a gets the value +Infinity ๐ฆ. If an expression lands outside the relevant range of ["-HUGE()":"HUGE()"], it gets replaced by -Inf or +Inf, whichever fits ๐ธ. Same deal with DATA i/Z'FFFFFFFF'/: that usually causes an integer overflow on most systems, but with -fno-range-check the value wraps around and i ends up initialized to -1 instead ๐.
โจ -fdefault-integer-8 โจ
sets the default integer and logical types to an 8-byte-wide type ๐. It also affects the kind of integer constants like 42. Unlike -finteger-4-integer-8, it does not promote variables that have an explicit kind declaration ๐
.
โจ -fdefault-real-8 โจ
sets the default real type to an 8-byte-wide type ๐ฅ. It also changes the kind of non-double real constants like 1.0. This option bumps the default width of DOUBLE PRECISION and double real constants like 1.d0 up to 16 bytes if possible ๐. If -fdefault-double-8 is given along with fdefault-real-8, then DOUBLE PRECISION and double real constants are not promoted ๐. Unlike -freal-4-real-8, fdefault-real-8 does not promote variables with explicit kind declarations โจ.
โจ -fdefault-real-10 โจ
sets the default real type to a 10-byte-wide type ๐ง. It also changes the kind of non-double real constants like 1.0. This option bumps the default width of DOUBLE PRECISION and double real constants like 1.d0 up to 16 bytes if possible ๐ซถ. If -fdefault-double-8 is given along with fdefault-real-10, then DOUBLE PRECISION and double real constants are not promoted ๐. Unlike -freal-4-real-10, fdefault-real-10 does not promote variables with explicit kind declarations ๐ธ.
โจ -fdefault-real-16 โจ
sets the default real type to a 16-byte-wide type ๐. It also changes the kind of non-double real constants like 1.0. This option bumps the default width of DOUBLE PRECISION and double real constants like 1.d0 up to 16 bytes if possible โญ. If -fdefault-double-8 is given along with fdefault-real-16, then DOUBLE PRECISION and double real constants are not promoted ๐ฆ. Unlike -freal-4-real-16, fdefault-real-16 does not promote variables with explicit kind declarations ๐
.
โจ -fdefault-double-8 โจ
sets the DOUBLE PRECISION type and double real constants like 1.d0 to an 8-byte-wide type ๐. If that's already the default, it does nothing ๐ซถ. This option stops -fdefault-real-8, -fdefault-real-10, and -fdefault-real-16 from promoting DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes ๐.
โจ -finteger-4-integer-8 โจ
promotes all INTEGER(KIND=4) entities to INTEGER(KIND=8) entities ๐ฅ. If KIND=8 isn't available, you'll get an error ๐. This one is a "use with care" option, and it might not suit your code ๐. Watch out for calls to external procedures, alignment in EQUIVALENCE and/or COMMON, generic interfaces, BOZ literal constant conversion, and I/O โ ๏ธ. It's recommended to inspect the intermediate representation of your translated Fortran code, which you can get with -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 six options promote all REAL(KIND=M) entities to REAL(KIND=N) entities ๐. If REAL(KIND=N) isn't available, you get an error ๐. Every other real kind is left alone ๐ธ. Like the integer one, these should be used with care and might not fit your codes ๐. Areas of concern are the same: calls to external procedures, alignment in EQUIVALENCE and/or COMMON, generic interfaces, BOZ literal constant conversion, and I/O ๐. Again, inspecting the intermediate representation with -fdump-tree-original is suggested ๐ง.
โจ -std=std โจ
picks the standard your program is supposed to follow ๐. It can be f95, f2003, f2008, f2018, gnu, or legacy ๐. The default is gnu, which is a superset of the latest Fortran standard and includes all the GNU Fortran extensions ๐. You'll still get warnings for obsolete extensions that aren't recommended in new code โ ๏ธ. legacy is basically the same but without those obsolete-extension warnings, so it can be handy for old non-standard programs ๐ซถ. f95, f2003, f2008, and f2018 are strict: they enforce conformance to Fortran 95, 2003, 2008, and 2018 respectively ๐. Anything beyond the language standard gives an error, and Fortran 77 features that are allowed but obsolescent in later standards get warnings ๐ฃ. The deprecated -std=f2008ts is just an alias for -std=f2018 ๐ฐ๏ธ. It only hangs around for backwards compatibility with earlier gfortran versions, so please don't use it anymore ๐
โโ๏ธ.
โจ -ftest-forall-temp โจ
boosts test coverage by forcing most forall assignments to use a temporary ๐งช.
๐ธ Enable and customize preprocessing ๐ธ
Preprocessor stuff ๐ง. For more detail, check the section Preprocessing and conditional compilation ๐.
โจ -cpp, -nocpp โจ
-cpp turns preprocessing on ๐. The preprocessor kicks in automatically if the file extension is .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03 or .F08 ๐
. Use -cpp if you want to manually enable preprocessing for any kind of Fortran file ๐ซถ.
To turn it off for files with any of those extensions, use the negative form: -nocpp ๐
โโ๏ธ.
The preprocessor runs in traditional mode ๐ฐ๏ธ. Any file-format restrictions, especially the line length limits, also apply to the preprocessed output ๐. So it might be a good idea to use -ffree-line-length-none or -ffixed-line-length-none ๐.
โจ -dM โจ
instead of the normal output, you get a list of #define directives for every macro defined during preprocessing, predefined ones included ๐. It's a great way to see what's predefined in your version of the preprocessor ๐ฆ. Assuming you don't have a file called foo.f90, this command:
touch foo.f90; gfortran -cpp -E -dM foo.f90
will show all the predefined macros ๐.
โจ -dD โจ
like -dM, except it skips the predefined macros, and it outputs both the #define directives and the result of preprocessing ๐ง. Both kinds of output go to the standard output file ๐ค.
โจ -dN โจ
like -dD, but it only emits macro names, not their expansions ๐ซถ.
โจ -dU โจ
like dD 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 ๐ฐ๏ธ. #undef directives are also output for macros that get tested but are undefined at that time ๐.
โจ -dI โจ
outputs #include directives in addition to the preprocessing result ๐.
โจ -fworking-directory โจ
turns on linemarkers in the preprocessor output that tell the compiler the current working directory at preprocessing time ๐บ๏ธ. After the initial linemarker, the preprocessor emits a second one with the current working directory followed by two slashes ๐ฆ. GCC uses that directory, if it's present, as the working directory in some debugging info formats ๐. This is implicitly enabled when debugging info is on, but you can block it with the negated form -fno-working-directory ๐
โโ๏ธ. If the -P flag is on the command line, this option does nothing, since no #line directives get emitted whatsoever ๐ซ.
โจ -idirafter dir โจ
searches dir for include files, but only after all the -I directories and the standard system directories have been exhausted ๐๏ธ. dir is treated as a system include directory ๐ . If dir begins with =, that = gets replaced by the sysroot prefix; see --sysroot and -isysroot ๐ฟ.
โจ -imultilib dir โจ
uses dir as a subdirectory of the directory holding target-specific C++ headers ๐.
โจ -iprefix prefix โจ
sets prefix as the prefix for later -iwithprefix options ๐ง. If the prefix is a directory, make sure to include the final / ๐
.
โจ -isysroot dir โจ
this is like the --sysroot option, but it only applies to header files ๐. See the --sysroot option for more info ๐.
โจ -iquote dir โจ
searches dir only for header files requested with #include "file" ๐ฌ. Those aren't searched for #include <file>, and this happens before all the -I directories and the standard system directories ๐. If dir begins with =, the = gets replaced by the sysroot prefix; see --sysroot and -isysroot ๐ซถ.
-isystem dirโ okay so this one searches dir for header files, but only after every-Idirectory and before the standard system directories ๐. It gets marked as a system directory too, so it gets the same special treatment as the standard ones โจ. If dir begins with"=", that"="gets swapped out for the sysroot prefix. See--sysrootand-isysroot๐ง.-nostdincโ no peeking in the standard system directories for headers ๐ Only the dirs you gave with-Ioptions (and the directory of the current file, if it makes sense) get searched.-undefโ don't predefine any system-specific or GCC-specific macros ๐ The standard predefined macros stay defined, though.-Apredicate=answerโ makes an assertion with the predicate predicate and the answer answer ๐. This is the preferred form over the older-A predicate(answer), which still works but is less iconic because it uses shell special characters ๐ .-A-predicate=answerโ cancels an assertion with the predicate predicate and the answer answer ๐ซ.-Cโ do not discard comments ๐ฌ. Every comment gets passed through to the output file, except comments inside processed directives, which get deleted along with the directive.
You should be prepared for side effects when using -C, bestie. It makes the preprocessor treat comments as tokens in their own right ๐ซ . For example, a comment at the start of what would be a directive line turns that line into an ordinary source line, because the first token is no longer a '#'.
Warning: this currently handles C-style comments only. The preprocessor does not yet recognize Fortran-style comments ๐.
-CCโ do not discard comments, including during macro expansion ๐งต. 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 -C side effects, -CC 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โ predefines name as a macro, with definition1๐ธ.-Dname=definitionโ the contents of definition get tokenized and processed as if they showed up during translation phase three in a#definedirective โจ. The definition gets truncated by embedded newline characters, so keep that in mind ๐.
If you're invoking the preprocessor from a shell or shell-like program, you may need the shell's quoting syntax to protect characters like spaces that mean something in shell syntax ๐.
Want a function-like macro on the command line? Write its argument list with surrounding parentheses before the equals sign (if any). Parentheses matter to most shells, so you'll need to quote the option ๐. With sh and csh, "-D'name(args...)=definition'" works ๐.
The -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 all -D and -U options ๐ง.
-Hโ prints the name of each header file used, along with the other normal activities ๐. Each name is indented to show how deep it sits in the#includestack ๐ช.-Pโ inhibits generation of linemarkers in the output from the preprocessor ๐ . This might be useful when running the preprocessor on something that isn't C code and will be sent to a program that might get confused by the linemarkers ๐ซถ.-Unameโ cancels any previous definition of name, whether it's built in or came from a-Doption ๐๏ธ.
โจ Options to request or suppress errors and warnings โจ
Errors are diagnostic messages reporting that the GNU Fortran compiler cannot compile the relevant piece of source code ๐จ. The compiler keeps going to report further errors so you can 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 the program ๐. Unless -Werror is specified, they don't stop the program from compiling ๐ซถ.
You can request lots of specific warnings with options starting with -W. For example, -Wimplicit requests warnings on implicit declarations ๐
. Each specific warning option also has a negative form starting with -Wno- that turns the warnings off, like -Wno-implicit ๐. This manual only lists one of the two forms, whichever one isn't the default ๐.
These options control the amount and kinds of errors and warnings GNU Fortran produces ๐ฅ:
-fmax-errors=nโ limits the maximum number of error messages to n. Once that's hit, GNU Fortran bails out instead of trying to keep processing the source code ๐. If n is0, there's no limit on the number of error messages produced โพ๏ธ.-fsyntax-onlyโ checks the code for syntax errors but doesn't actually compile it ๐. This will generate module files for each module in the code, but no other output file ๐.-Wpedantic,-pedanticโ issues warnings for uses of extensions to Fortran ๐ง.-pedanticalso applies to C-language constructs where 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, though, certain GNU extensions and traditional Fortran features are supported too. With this option on, many of them 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 very welcome ๐.
This should be used alongside -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 think 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 started the continuation ๐ง .
-Warray-temporariesโ warns about array temporaries the compiler generates ๐๏ธ. The info from this warning is sometimes useful for optimization, so you can avoid those temporaries ๐.-Wc-binding-typeโ warns if a variable might not be C interoperable ๐. Especially, it warns if the variable was declared with an intrinsic type using the 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 get 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 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 โ๏ธ. As an 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 so this behavior never gets triggered, and it always links to the intrinsic regardless of the selected standard ๐ง.-Wno-overwrite-recursiveโ do not 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 suppress the warning when you know recursion isn't broken ๐ . It's useful for build environments that use-Werror๐ ๏ธ.-Wreal-q-constantโ produces a warning if a real-literal-constant contains a"q"exponent-letter ๐.-Wsurprising: okay so this one yells when your code gives off "suspicious" vibes ๐. It's technically legal, but these usually mean you made a mistake, bestie. It currently warns in these situations:- An
INTEGER SELECTconstruct has aCASEthat can never match, because its lower value is greater than its upper value. - A
LOGICAL SELECTconstruct has threeCASEstatements. - A
TRANSFERhas 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 becomes an error ๐. - A
CHARACTERvariable is declared with a negative length.
- An
-Wtabs: tabs are accepted as whitespace by default, but they are not members of the Fortran Character Set, so ngl that's a little 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. Heads up,-Wtabsis already active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall๐.-Wundefined-do-loop: warns if aDOloop with a step of either1or-1hits an underflow or an overflow while its induction variable is running ๐. This one is implied by-Wall.-Wunderflow: warns when a numerical constant expression underflows during compilation. It's on by default, so you already get this one 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 your calls resolve to the right procedure ๐ฆ. This one is implied by-Wall.-Wuse-without-only: warns if aUSEstatement doesn't have anONLYqualifier, which means it quietly imports every public entity from the module ๐ธ.-Wunused-dummy-argument: warns about unused dummy arguments. This one is implied by-Wall.-Wunused-parameter: okay, this one is a plot twist ๐ญ. Unlike gcc's version, gfortran's-Wunused-parameterdoesn't care about unused dummy arguments (that's-Wunused-dummy-argument's job). Instead it looks at unusedPARAMETERvalues. It's implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commons: by default, gfortran warns whenever variables get padded for proper alignment inside aCOMMONblock. You can switch that off with-Wno-align-commons. Also see-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 allocation or reallocation code for an allocatable array variable of intrinsic type during intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature can hurt performance ๐ฅ. If the array is already allocated with the correct shape, try a whole-array array-spec (like(:,:,:)) on the left-hand side to skip the reallocation check. Note that the warning can show up even when the compiler would optimize those checks away anyway, for example when the right-hand side contains the same variable multiplied by a scalar. Also see-frealloc-lhs.-Wrealloc-lhs-all: warns whenever the compiler inserts allocation or reallocation code for an allocatable variable. That includes scalars and derived types ๐ .-Wcompare-reals: warns when you compare real or complex values for equality or inequality. This one is implied by-Wextra.-Wtarget-lifetime: warns if the pointer in a pointer assignment might outlive its target. This one is implied by-Wall.-Wzerotrip: warns if aDOloop is known at compile time to run zero times. This one is 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. Something like this is the kind of thing it flags:
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 right after the source program has been translated into the internal representation. This is mostly useful for debugging the GNU Fortran compiler itself. The output can change between releases, and this option might also trigger 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 can change between releases, and this option might also trigger internal compiler errors for features that were only recently added.-fdump-parse-tree: outputs the internal parse tree right after the source program has been translated into the internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output can change between releases, and this option might also trigger internal compiler errors for features that were only recently added.
โ ๏ธ This option is deprecated. Use -fdump-fortran-original instead.
-fdump-fortran-global: outputs a list of the global identifiers after translation into the middle-end representation. Mostly useful for debugging the GNU Fortran compiler itself. The output can change between releases, and this option might also trigger 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 is aborted, leaving behind a core file that's useful for debugging. Thelistis a comma-separated list (it can be empty) of these exceptions:invalid: an invalid floating-point operation, such asSQRT(-1.0).zero: division by zero.overflow: an overflow in a floating-point operation.underflow: an underflow in a floating-point operation.inexact: loss of precision during an operation.denormal: an operation performed on a denormal value.
The first five exceptions match the five IEEE 754 exceptions. The last one, denormal, isn't part of the IEEE 754 standard, 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 a plan for dealing with them, turning on traps for those three is probably a good idea ๐ซถ.
If the option appears more than once on the command line, the lists get joined together. '"ffpe-trap="list1 "ffpe-trap="list2 is the same as "ffpe-trap="list1,list2.
Once an exception is enabled it can't be disabled, since there's no negative form ๐ โโ๏ธ.
Most floating-point operations lose some precision because of rounding, so ffpe-trap=inexact is probably not very interesting 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 ๐. Thelistcan benone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (Check-ffpe-trapfor what each exception means.)
If the option is used more than once on the command line, only the last one counts.
By default, a summary is shown for all exceptions except inexact.
-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 print a backtrace of the error ๐ชต.-fno-backtraceturns that backtrace generation off. This only matters when compiling the Fortran main program.
๐ Options for directory search
These options control how GNU Fortran looks for files pulled in 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: affects how theINCLUDEdirective gets interpreted (and also the#includedirective of thecpppreprocessor). Also,-IandINCLUDEbehave pretty much the same as-Iwith#includein thecpppreprocessor when it comes to finding header.gcc files and other such things ๐.
This path is also searched for .mod files when previously compiled modules are needed by a USE statement.
-Jdir: specifies where to put the.modfiles for compiled modules. It's also added to the list of directories searched by aUSEstatement.
The default is the current directory.
-fintrinsic-modules-path dir: specifies where the pre-compiled intrinsic modules live, if they aren't in the default location the compiler expects ๐.
๐ Influencing the linking step
These options kick in 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 providelibgfortranas both a shared and a static library, this forces the use of the static version. If no shared version oflibgfortranwas 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 bestie, this one decides how data is represented in unformatted files ๐พโจ The valid values arenative(the default ๐ ),swap(swaps between big- and little-endian ๐),big-endian(uses big-endian representation for unformatted files ๐), andlittle-endian(uses little-endian representation for unformatted files ๐).
Heads up: this only has an effect when you use it in the main program ๐ The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable both override whatever -fconvert sets ๐ซถ
-frecord-marker=lengthโ this sets the length of record markers for unformatted files ๐ฆ The valid values are4and8, and the default is4. Older gfortran versions used8on most systems, so this is a glow-up ๐ If you need to read or write files that work with earlier gfortran versions, use-frecord-marker=8.-fmax-subrecord-length=lengthโ sets the maximum length for a subrecord ๐ง The biggest value you can use is2147483639, which is also the default. Honestly it's only really useful for the gfortran testsuite ๐งช-fsign-zeroโ when this is enabled ๐ธ zero-valued floats with the sign bit set get written as negative numbers in formatted output and get treated as negative by theSIGNintrinsic.-fno-sign-zeroskips printing the negative sign on zero (or on values rounded to zero for I/O) and treats zero as positive in theSIGNintrinsic, which keeps things compatible 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 ๐ง They're giving main character energy for your compiled code ๐
Most of them come in positive and negative forms, and the negative form of -ffoo is -fno-foo. In the list below, only the non-default form is shown, so you can figure out the other one by removing no- or adding it ๐
-fno-automaticโ this one treats each program unit (except the ones marked asRECURSIVE) like theSAVEstatement was applied to every local variable and array in it ๐ It doesn't touch common blocks. Some Fortran compilers call this option-staticor-save๐ The default is-fautomatic, which puts local variables smaller than the value given by-fmax-stack-var-sizeon the stack. If you want no static memory at all, use-frecursiveinstead ๐
Local variables or arrays with an explicit SAVE attribute get silently ignored, unless you add the -pedantic option ๐
-ff2cโ generates code that's designed to be compatible with code fromg77andf2c๐
Okay, the calling conventions used by g77 (originally from f2c) say that functions returning default REAL actually return the C type double. Functions returning COMPLEX instead hand back their values through an extra argument in the calling sequence, which points to where the return value should be stored ๐ฅน With the default GNU calling conventions, those 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. This option also implies -fsecond-underscore, unless you explicitly ask for -fno-second-underscore ๐
This doesn't affect code that interfaces with the libgfortran library ๐
Caution: It's not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions. CallingCOMPLEXor defaultREALfunctions between program parts that were 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โ this stops GNU Fortran from appending underscores to the names of entities in your Fortran source file ๐
With -funderscoring in effect (the default vibe โจ), GNU Fortran adds one underscore to external names that don't already have any. That's so the code matches what plenty of UNIX Fortran compilers produce ๐ซถ
Caution: GNU Fortran's default behavior is incompatible withf2candg77. If you want object files from GNU Fortran to play nice with object code made by those tools, use the-ff2coption ๐จ
Using -fno-underscoring isn't recommended unless you're experimenting with things like fitting GNU Fortran into existing system environments (vis-a-vis existing libraries, tools, and so on) ๐งช
Let's look at an 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:
i = j_() + max_count__(&my_var__, &lvar);
With -fno-underscoring, that same statement gets implemented as:
i = j() + max_count(&my_var, &lvar);
Using -fno-underscoring lets you use your own names directly while debugging, and when you're hooking GNU Fortran code up to other languages ๐ง
Note that just because the names match doesn't mean the interface GNU Fortran uses for an external name matches the interface some other language uses for that same name ๐ฅด Getting code from GNU Fortran to link with code from another compiler, using this or any other method, is only a small part of the job. Getting both compilers' code to agree on things other than naming can take a lot of effort, and unlike naming mismatches, linkers usually can't detect disagreements in those other areas ๐ฉ
Also, with -fno-underscoring, the lack of appended underscores means a user-defined external name could totally clash with a name in a system library โก That can make unresolved-reference bugs super hard to find, since they might only show up at program run time as weird buggy behavior ๐
In future versions of GNU Fortran, the hope is to improve naming and linking so that debugging always uses the names as they appear in the source ๐ฎ Even if the linker sees mangled names (to prevent accidental linking between procedures with incompatible interfaces), you'd still debug with your source names ๐
-fsecond-underscoreโ by default, GNU Fortran appends one underscore to external names ๐ท With 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 with 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.
With this option, an external name such as MAX_COUNT gets 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 using the -ff2c option ๐ซง
-fcoarray=<keyword>โ this one controls coarray support, and you pick one of these keywords ๐งโ๐คโ๐งnoneโ disables coarray support. Using coarray declarations and image-control statements will throw a compile-time error ๐ซ (Default)singleโ single-image mode, meaningnum_images()is always one 1๏ธโฃlibโ library-based coarray parallelization. You need to link a suitable GNU Fortran coarray library for this one ๐ฆ
-fcheck=<keyword>โ this turns on the generation of run-time checks ๐ The argument should be a comma-delimited list of the keywords below. Puttingno-in front of a check disables it, if a previous specification turned it on ๐ โโ๏ธallโ enables all run-time tests of-fcheck๐ฏarray-tempsโ warns at run time when a temporary array had to be generated for passing an actual argument. The info from this warning can be handy for optimization, so you can 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 makes sure all string lengths are equal for character array constructors without an explicit typespec ๐งต- Some checks require that
-fcheck=boundsis set when compiling the main program ๐ - Note: in the future this may also include other forms of checking, e.g., checking substring references ๐ฎ
- Some checks require that
doโ enables run-time checks for invalid modification of loop iteration variables ๐memโ enables run-time checks for memory allocation ๐ง- Note: this option doesn't affect explicit allocations using the
ALLOCATEstatement, which are always checked anyway ๐
- Note: this option doesn't affect explicit allocations using the
pointerโ enables run-time checks for pointers and allocatables ๐recursionโ enables run-time checks for recursively called subroutines and functions that aren't marked as recursive. See also-frecursive๐- Note: this check doesn't work for OpenMP programs, and it's disabled if you use it together with
-frecursiveand-fopenmp๐ซ
- Note: this check doesn't work for OpenMP programs, and it's disabled if you use it together with
Example time ๐ Say you have a file called foo.f90. The command:
gfortran -fcheck=all,no-array-temps foo.f90
will compile the file with all checks enabled as listed above, except the warnings for generated array temporaries ๐ธ
-fbounds-checkโ this is a deprecated alias for-fcheck=bounds๐ฅ-ftail-call-workaround,-ftail-call-workaround=nโ some C interfaces to Fortran codes break the gfortran ABI by leaving out the hidden character length arguments as described in ๐
Aside: the original page trails off right there, so there's no reference after "described in". It's not my fault, bestie ๐ญ
Anyway, this can lead to crashes, because pushing arguments for tail calls can overflow the stack ๐ฅ
To keep older binary packages working, this flag turns off tail call optimization for gfortran procedures that take character arguments. -ftail-call-workaround=2 turns it off in every gfortran procedure with character arguments. -ftail-call-workaround=1, or plain -ftail-call-workaround, only does it in gfortran procedures with character arguments that call implicitly prototyped procedures.
Heads up ๐: using this can lead to problems, including crashes from running out of stack space.
It is very strongly recommended that you fix the code in question instead ๐ซถ. The -fc-prototypes-external option can generate prototypes that follow gfortran's ABI, which you can then include in your source code.
Support for this option will likely be withdrawn in a future release of gfortran ๐ญ.
You can switch this off with -fno-tail-call-workaround, or the equivalent -ftail-call-workaround=0.
The default is currently -ftail-call-workaround, but that's going to change in future releases ๐ฆ.
-fcheck-array-temporariesโ This is a deprecated alias for-fcheck=array-temps, so just use the newer spelling ๐ .-fmax-array-constructor=nโ This lets you raise 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 can lead to long compile times and excessively large object files ๐.
The default value for n is 65535.
-fmax-stack-var-size=nโ This sets the size in bytes of the biggest array that gets put on the stack ๐ฆ. If an array goes over that size, static memory is used instead, except in procedures markedRECURSIVE. To allow recursive procedures that don't have aRECURSIVEattribute, or for parallel programs, use-frecursive. To never use the stack at all, use-fno-automatic.
This option currently only affects local arrays declared with constant bounds, and it may not apply to every character variable. Future versions of GNU Fortran may improve this behavior ๐ธ.
The default value for n is 65536.
-fstack-arraysโ This makes the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory ๐ฅ. If your program uses really large local arrays, you may need to raise your runtime stack limits on some operating systems. This flag is enabled by default at the-Ofastoptimization level, unless-fmax-stack-var-sizeis specified.-fpack-derivedโ This tells GNU Fortran to pack derived type members as tightly 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 โจ. However, it can add significant overhead to the function call, especially when the passed data is noncontiguous.
-fshort-enumsโ This is here for interoperability with C code that was compiled with-fshort-enums๐ค. GNU Fortran will pick the smallestINTEGERkind that a given enumerator set fits in, and give all of 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 tofoobelow:
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
When -finline-arg-packing is in effect, that packing is done by inline code ๐. This allows more optimization, but it increases code size.
-finline-arg-packing is implied by any of the -O options, except when optimizing for size with -Os ๐. If the code has a huge number of arguments that need packing, code size and compile time can get out of hand. In that case, it may be better to turn this option off. You can find instances of packing by using -Warray-temporaries.
-fexternal-blasโ This makes gfortran call BLAS functions for some matrix operations, likeMATMUL, instead of using its own algorithms ๐งฎ. That happens when the matrices are bigger than a given limit (see-fblas-matmul-limit). This can pay off if an optimized vendor BLAS library is available ๐. The BLAS library has to be specified at link time.-fblas-matmul-limit=nโ This only matters when-fexternal-blasis in effect ๐ฅ. Matrix multiplication with matrices of size larger than or equal tongets done by calls to BLAS functions, and everything smaller is 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 matrix size can't be determined at compile time, because code for both cases gets generated. Setting-finline-matmul-limit=0turns inlining off 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 for n is 30. The -fblas-matmul-limit option can be used to change this value.
-frecursiveโ This 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โ These options set initial values for local variables ๐.-finit-local-zerotells the compiler to initialize localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes.
Finer-grained initialization is available through -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real and imaginary parts of local COMPLEX variables), -finit-logical=<true|false>, and -finit-character=n, where n is an ASCII character value.
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 turn them into quiet NaNs, and trapping needs to be enabled (for example, with -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.
Last but not least, 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 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-commonsturns automatic alignment off. Use the same form of this option for all files that share aCOMMONblock. To avoid potential alignment issues inCOMMONblocks, it's recommended to order objects from largest to smallest ๐ท.-fno-protect-parensโ By default, parentheses in expressions are honored at all optimization levels, so the compiler doesn't re-associate anything ๐. Using-fno-protect-parenslets the compiler reorderREALandCOMPLEXexpressions to produce faster code. For the re-association optimization,-fno-signed-zerosand-fno-trapping-mathalso need to be in effect. 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 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 performs front-end optimization by manipulating parts of the Fortran parse tree ๐. It's enabled by default by any-Ooption except-O0and-Og. Optimizations turned on by this option include:
Okay so -ffrontend-optimize also does these bits, bestie ๐
- inlining calls to
MATMUL๐ง - elimination of identical function calls within expressions โจ
- removing unnecessary calls to
TRIMin comparisons and assignments ๐ - replacing
TRIM(a)witha(1:LEN_TRIM(a))๐ฆ - short-circuiting of logical operators (
.AND.and.OR.) ๐ฅ
Not into it? You can deselect the whole thing with -fno-frontend-optimize ๐
-ffrontend-loop-interchangeโ this one tries to swap loops in the Fortran front end whenever 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 niche ๐
๐ ENVIRONMENT ๐
Honestly, gfortran doesn't read any environment variables to control itself beyond the ones that already affect gcc. So if you're already set up for gcc, you're set for gfortran too ๐
๐ BUGS ๐
Want to report a bug? Check out <file:///usr/share/doc/gcc-10/README.Bugs> for the instructions ๐ซถ
๐ฆ SEE ALSO ๐ฆ
Go deeper with gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1) and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb ๐โจ
๐ AUTHOR ๐
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.
You're allowed to copy, distribute and/or modify this doc under the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation ๐ฆ The Invariant Sections are "Funding Free Software", the Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). A copy of the license is included in the gfdl(7) man page.
- (a) The FSF's Front-Cover Text is: "A GNU Manual"
- (b) The FSF's Back-Cover Text is: "You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development."
That's the whole page, bestie! โจ Huge thanks to the gcc-10 crew for keeping it glowing since 2023-07-07 ๐ Now go be a GFORTRAN(1) main character ๐๐
๐ฆ where this page comes from
- ubuntu jammy: gfortran-10-alpha-linux-gnu 10.5.0-1ubuntu1~22.04cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms