GFORTRAN(1)
๐ GFORTRAN(1) ยท GNU Manual ๐
โจ NAME โจ
okay so bestie, this is gfortran, aka 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...
Only the most useful options are squeezed into the synopsis, so scroll down for the rest ๐ซถ
๐ DESCRIPTION ๐
The gfortran command is literally giving gcc energy, because it supports all the options that gcc supports โจ Only the options specific to GNU Fortran get documented here, so no need to re-read the GCC stuff ๐
All GCC and GNU Fortran options work with both gfortran and gcc, plus any other drivers built at the same time (like g++) ๐ Adding GNU Fortran to the GCC distribution means every relevant driver accepts GNU Fortran options. Iconic, honestly ๐
Some options come in pairs. The negative form of -ffoo is -fno-foo, and this manual only documents whichever one isn't the default ๐
๐ OPTIONS ๐
Here's the vibe check of every option specific to GNU Fortran, sorted into groups by type ๐ The explanations come in the sections after this 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
-fdebug-aux-vars -fdump-fortran-global -fdump-parse-tree
-ffpe-trap=list -ffpe-summary=list
๐ Directory Options ๐
-Idir -Jdir -fintrinsic-modules-path dir
๐ Link Options ๐
-static-libgfortran
โฑ๏ธ Runtime Options โฑ๏ธ
-fconvert=conversion -fmax-subrecord-length=length
-frecord-marker=length -fsign-zero
๐ค Interoperability Options ๐ค
-fc-prototypes -fc-prototypes-external
๐ ๏ธ Code Generation Options ๐ ๏ธ
-faggressive-function-elimination -fblas-matmul-limit=n
-fbounds-check -ftail-call-workaround -ftail-call-workaround=n
-fcheck-array-temporaries
-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>
-fcoarray=<none|single|lib> -fexternal-blas -ff2c
-ffrontend-loop-interchange -ffrontend-optimize -finit-character=n
-finit-integer=n -finit-local-zero -finit-derived
-finit-logical=<true|false> -finit-real=<zero|inf|-inf|nan|snan>
-finline-matmul-limit=n -finline-arg-packing
-fmax-array-constructor=n -fmax-stack-var-size=n -fno-align-commons
-fno-automatic -fno-protect-parens -fno-underscoring
-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive
-frepack-arrays -fshort-enums -fstack-arrays
๐๏ธ Options controlling Fortran dialect ๐๏ธ
The options below are the ones that control the details of the Fortran dialect the compiler accepts ๐
-ffree-form,-ffixed-formโ Picks the layout the source file uses. Free form showed up in Fortran 90, while fixed form was the traditional look of older Fortran programs. If you specify neither, the source form gets figured out from the file extension ๐ง-fall-intrinsicsโ Causes every intrinsic procedure (including the GNU-specific extensions) to be accepted โจ This is handy alongside-std=f95if you want standard-compliance but still want the full set of intrinsics gfortran has. As a consequence,-Wintrinsics-stdgets ignored, and no user-defined procedure that shares a name with an intrinsic will be called, unless it's explicitly declared "EXTERNAL" ๐-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 as an error. This option downgrades the error to a warning, and the only way to turn that warning off is to disable all warnings with-w. Only a single occurrence per argument gets flagged by this warning.-fallow-argument-mismatchis implied by-std=legacy.
Using this option is strongly discouraged ๐ญ It's possible to 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 show up in a limited number of contexts in standard-conforming Fortran. This option downgrades an error condition 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โ Turns on special treatment for lines that begin with "d" or "D" in fixed-form sources ๐ฆ With-fd-lines-as-code, they're treated as if the first column held a blank. With-fd-lines-as-comments, they're treated as comment lines.-fdecโ DEC compatibility mode ๐ It enables extensions and other features that mimic the default behaviour of older compilers (such as DEC). These features are non-standard and should be avoided at all costs ๐ For the details on GNU Fortran's version of these extensions, check the full documentation.
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 -fdec-format-defaults
If -fd-lines-as-code/-fd-lines-as-comments are unset, then -fdec also sets -fd-lines-as-comments โจ
-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 (on top of'%') ๐ง This is only here for compatibility. Fortran 90 derived types are the better choice wherever you can use them ๐-fdec-intrinsic-intsโ Enables the 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...) so older code stays compatible ๐ธ-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 an INCLUDE statement,INCLUDEdoesn't have to sit on a single line and can use line continuations.-fdec-format-defaultsโ Lets the format specifiersF,GandIbe used without width specifiers. Default widths get used instead ๐-fdec-blank-format-itemโ Enables a blank format item at the end of a format specification, i.e. nothing following 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 should 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 combinations get expanded:\a,\b,\f,\n,\r,\t,\v,\\, and\0, which turn into the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. On top of that,"\x"nn,"\u"nnnnand"\U"nnnnnnnn(where each n is 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โ 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 may also be none, meaning the entire line is meaningful and continued character constants never get implicit spaces appended to fill out the line. -ffixed-line-length-0 means the same thing as -ffixed-line-length-none โจ
-fno-pad-sourceโ By default, fixed-form lines get spaces assumed (as if padded to that length) after the ends of short fixed-form lines ๐ง That padding 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 get implicit spaces appended to fill out the line ๐-ffree-line-length-nโ Okay so this one sets the column where free-form source lines get cut off ๐. Anything past that column is ignored. The default is132. Setntononeif you want the entire line to count, no cutoff. And-ffree-line-length-0is literally the same thing as-ffree-line-length-noneโจ.-fmax-identifier-length=nโ Sets the max identifier length ๐ฆ. Typical values are31for Fortran 95 and63for Fortran 2003 and Fortran 2008.-fimplicit-noneโ No implicit typing allowed, unless you override it with explicitIMPLICITstatements ๐ซถ. It's basically the same as slappingimplicit noneat the top of every procedure.-fcray-pointerโ Turns on the Cray pointer extension, which gives you C-like pointer functionality ๐ง.-fopenaccโ Turns on the OpenACC extensions ๐ธ. That includes!$accdirectives in free form, plusc$acc,*$acc, and!$accdirectives in fixed form. It also covers the!$conditional compilation sentinels in free form, and thec$,*$, and!$sentinels in fixed form. And when linking, it makes sure the OpenACC runtime library gets linked in too.-fopenmpโ Turns on the OpenMP extensions ๐. That includes!$ompdirectives in free form, plusc$omp,*$omp, and!$ompdirectives in fixed form. It also covers the!$conditional compilation sentinels in free form, and thec$,*$, and!$sentinels in fixed form. When linking, it arranges for the OpenMP runtime library to be linked in. And heads up,-fopenmpimplies-frecursive๐.-fno-range-checkโ Turns off range checking on the results of simplifying constant expressions during compilation ๐. For example, GNU Fortran will throw an error at compile time when simplifyinga = 1. / 0. With this option, there's no error, andagets the value+Infinity. If an expression evaluates to a value outside the relevant range of["-HUGE()":HUGE()], it gets replaced by-Infor+Inf, whichever fits. Similarly,DATA i/Z'FFFFFFFF'/causes an integer overflow on most systems, but with-fno-range-checkthe value wraps around andigets initialized to-1instead.-fdefault-integer-8โ Sets the default integer and logical types to an 8 byte wide type ๐ฅ. This also affects the kind of integer constants like42. Unlike-finteger-4-integer-8, it does not promote variables with explicit kind declaration.-fdefault-real-8โ Sets the default real type to an 8 byte wide type โจ. This also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-8, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations.-fdefault-real-10โ Sets the default real type to a 10 byte wide type ๐. This also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-10,fdefault-real-10does not promote variables with explicit kind declarations.-fdefault-real-16โ Sets the default real type to a 16 byte wide type ๐. This also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations.-fdefault-double-8โ Sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8 byte wide type ๐. If that's already the default, it does nothing. This option stops-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes.-finteger-4-integer-8โ Promotes allINTEGER(KIND=4)entities toINTEGER(KIND=8)entities ๐ฆ. IfKIND=8is unavailable, an error gets issued. Use this one with care, because it may not be suitable for your codes. Areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. Inspecting the intermediate representation of the translated Fortran code, produced by-fdump-tree-original, is suggested.-freal-4-real-8,-freal-4-real-10,-freal-4-real-16,-freal-8-real-4,-freal-8-real-10,-freal-8-real-16โ Promotes allREAL(KIND=M)entities toREAL(KIND=N)entities ๐ . IfREAL(KIND=N)is unavailable, an error gets issued. The-freal-4-flags also affect the default real kind, and the-freal-8-flags also affect the double-precision real kind. All other real-kind types are unaffected. The promotion also applies to real literal constants of default and double-precision kind, with a specified kind number of 4 or 8 respectively. However,-fdefault-real-8,-fdefault-real-10,-fdefault-real-10, and-fdefault-double-8take precedence for the default and double-precision real kinds, both for real literal constants and for declarations without a kind number. Note that forREAL(KIND=KIND(1.0)), the literal may get promoted and then the result may get promoted again.
These options should be used with care and may not be suitable for your codes ๐ญ. Areas of possible concern include calls to external procedures, alignment in EQUIVALENCE and/or COMMON, generic interfaces, BOZ literal constant conversion, I/O, and calls to intrinsic procedures when passing a value to the kind= dummy argument. Inspecting the intermediate representation of the translated Fortran code, produced by -fdump-fortran-original or -fdump-tree-original, is suggested.
-std=stdโ Specifies the standard your program is expected to conform to ๐. It may be one off95,f2003,f2008,f2018,gnu, orlegacy. The default isgnu, which is a superset of the latest Fortran standard that includes all of the extensions GNU Fortran supports, although warnings get given for obsolete extensions not recommended for new code. Thelegacyvalue is equivalent but without the warnings for obsolete extensions, and it may be useful for old non-standard programs. Thef95,f2003,f2008, andf2018values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008, and Fortran 2018 standards respectively. Errors get given for all extensions beyond the relevant language standard, and warnings get given for the Fortran 77 features that are permitted but obsolescent in later standards.
The deprecated option-std=f2008tsacts as an alias for-std=f2018. It's only there for backwards compatibility with earlier gfortran versions, so please don't use it any more ๐.
-ftest-forall-tempโ Boosts test coverage by forcing mostforallassignments to use a temporary ๐งช.
โจ Enable and customize preprocessing โจ
Preprocessor related options ๐ท. See section Preprocessing and conditional compilation for more detailed information on preprocessing in gfortran.
-cpp,-nocppโ-cppturns on preprocessing ๐. The preprocessor gets invoked automatically if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03, or.F08. Use this flag to manually enable preprocessing of any kind of Fortran file.
To disable preprocessing of files with any of the extensions listed above, use the negative form: -nocpp ๐
.
The preprocessor runs in traditional mode. Any restrictions of the file format, especially the limits on line length, apply to the preprocessed output as well, so it might be advisable to use the -ffree-line-length-none or -ffixed-line-length-none options ๐ฆ.
-dMโ Instead of the normal output, this generates a list of#definedirectives for all the macros defined during the execution of the preprocessor, including predefined macros ๐. It's a way of finding out what's predefined in your version of the preprocessor. Assuming you have no filefoo.f90, the command:
touch foo.f90; gfortran -cpp -E -dM foo.f90
will show all the predefined macros.
-dDโ Like-dM, except in two respects: it does not include the predefined macros, and it outputs both the#definedirectives and the result of preprocessing ๐ง. Both kinds of output go to the standard output file.-dNโ Like-dD, but emits only the macro names, not their expansions ๐ซง.-dUโ LikedD, except only macros that are expanded, or whose definedness is tested in preprocessor directives, are output ๐ธ. The output is delayed until the use or test of the macro, and#undefdirectives are also output for macros tested but undefined at the time.-dIโ Outputs#includedirectives in addition to the result of preprocessing ๐.-fworking-directoryโ Enables generation of linemarkers in the preprocessor output that let the compiler know the current working directory at the time of preprocessing ๐. When this option is enabled, the preprocessor emits, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC will use this directory, when it's present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats. This option is implicitly enabled if debugging information is enabled, but you can inhibit it with the negated form-fno-working-directory. If the-Pflag is present on the command line, this option has no effect, since no#linedirectives are emitted whatsoever.-idirafter dirโ Searchesdirfor include files, but does it after all the directories specified with-Iand the standard system directories have been exhausted ๐ง.diris treated as a system include directory. Ifdirbegins with=, then the=gets replaced by the sysroot prefix; see--sysrootand-isysroot๐.-imultilib dir: okay so this one lets you use dir as a subdirectory of the directory that holds the target-specific C++ headers ๐ฆ-iprefix prefix: sets prefix as the prefix for later-iwithprefixoptions โจ If the prefix is a directory, make sure you include the final/, bestie ๐-isysroot dir: this is giving--sysrootvibes, but it only applies to header files ๐ Check out--sysrootfor the full tea.-iquote dir: searches dir only for headers requested with#include "file". They are NOT searched for#include <file>๐ This happens before all the-Idirectories and before the standard system directories. If dir starts with=, that=gets swapped out for the sysroot prefix. See--sysrootand-isysroot.-isystem dir: searches dir for headers after all the-Idirectories but before the standard system directories ๐ It gets marked as a system directory, so it gets the same special treatment as the standard ones. If dir starts with=, the=gets replaced by the sysroot prefix. See--sysrootand-isysroot.-nostdinc: don't search the standard system directories for headers ๐ซ Only the directories you gave with-Ioptions (plus the directory of the current file, if it applies) 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). That one still works, but this one doesn't use shell special characters, so it's way less drama.-A-predicate=answer: cancels an assertion with the predicate predicate and the answer answer ๐ซถ-C: don't throw away comments! All comments get passed through to the output file, except comments inside processed directives. Those get deleted along with the directive ๐ญ
Heads up, you should be prepared for side effects with -C. It makes the preprocessor treat comments as tokens in their own right ๐ For example, comments sitting 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 ๐ This is like-C, except comments contained within macros also get passed through to the output file wherever the macro is expanded.
On top of the side effects of -C, the -CC option converts all C++-style comments inside a macro into C-style comments. This stops 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 the definition1โญ-Dname=definition: the contents of definition get tokenized and processed as if they appeared during translation phase three in a#definedirective ๐ธ In particular, the definition gets cut off by embedded newline characters.
If you're invoking the preprocessor from a shell or shell-like program, you may need the shell's quoting syntax to protect characters like spaces, since they have a meaning in shell syntax ๐
If you want to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if there is one). Parentheses mean something 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: 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: stops the preprocessor from generating linemarkers in its output ๐ This might be useful when you run the preprocessor on something that isn't C code and will get sent to a program that could get confused by the linemarkers.-Uname: cancels any previous definition of name, whether it was built in or provided with a-Doption ๐
โจ Options to request or suppress errors and warnings โจ
Errors are diagnostic messages that report the GNU Fortran compiler can't compile the relevant piece of source code ๐ The compiler keeps going so it can report more 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 stop the program from compiling.
You can request lots of specific warnings with options beginning -W. For example, -Wimplicit requests warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- that turns warnings off, like -Wno-implicit. This manual lists only 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: limits the maximum number of error messages to n ๐ Once it hits that, GNU Fortran bails out rather than trying to keep processing the source code. If n is0, there is no limit on the number of error messages produced.-fsyntax-only: checks the code for syntax errors without actually compiling it โจ This will generate module files for each module present in the code, but no other output file.-Wpedantic,-pedantic: issues warnings for uses of extensions to Fortran ๐ค-pedanticalso applies to C-language constructs where they show up in GNU Fortran source files, like using\ein a character constant within a directive such as#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, many of them get rejected ๐ โโ๏ธ
Some users try to use -pedantic to check programs for conformance. They soon find it doesn't quite do what they want: it finds some nonstandard practices, but not all ๐ญ Improvements to GNU Fortran in this area are welcome, though.
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018.
-pedantic-errors: like-pedantic, except errors are produced rather than 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 started the continuation.-Warray-temporaries: warns about array temporaries generated by the compiler ๐๏ธ 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 ๐ In particular, it warns if the variable was declared using an intrinsic type with the default kind, instead of using a kind parameter defined for C interoperability in the intrinsicISO_C_Bindingmodule. This option is implied by-Wall.-Wcharacter-truncation: warns when a character assignment will truncate the assigned string โ๏ธ-Wline-truncation: warns when a source code line will be truncated ๐ This option is implied by-Wall. For free-form source code, the default is-Werror=line-truncation, so truncations get reported as errors.-Wconversion: warns about implicit conversions that are likely to change the value of the expression after conversion ๐ Implied by-Wall.-Wconversion-extra: warns about implicit conversions between different types and kinds ๐ This option does not imply-Wconversion.-Wextra: enables some warning options for usages of language features that may be problematic ๐ง This currently includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchange: warns when-ffrontend-loop-interchangeis used to 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 asEXTERNAL๐ซฃ-Winteger-division: warns if a constant integer division truncates its result ๐ As an example,3/5evaluates to0.-Wintrinsics-stdโ โจ Heads up, bestie! If gfortran finds a procedure named like an intrinsic that isn't available in the standard you picked (with-std), it'll warn you and treat it as anEXTERNALprocedure instead ๐. If you never want that to happen,-fall-intrinsicsalways links to the intrinsic, no matter which standard you chose ๐-Wno-overwrite-recursiveโ ๐ธ Skips the warning when-fno-automaticis used with-frecursive. Recursion gets broken if the relevant local variables don't have theAUTOMATICattribute explicitly declared. Use this when you know recursion isn't broken and you just want the noise gone. It's super useful for build setups that use-Werror๐ซถ-Wreal-q-constantโ ๐ฆ Warns if a real literal constant has aqexponent letter.-Wsurprisingโ ๐ Warns about "suspicious" code. It's technically legal, but it usually means someone made a mistake. Right now it fires 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 aren't members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported.-Wtabsmakes gfortran warn whenever it spots a tab. It's active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Walltoo โจ-Wundefined-do-loopโ ๐ Warns if aDOloop with step either 1 or -1 hits an underflow or overflow while its induction variable is iterating. This one's implied by-Wall.-Wunderflowโ ๐ Warns when numerical constant expressions are encountered that give an UNDERFLOW during compilation. It's on by default, so you get it for free ๐-Wintrinsic-shadowโ ๐ต๏ธ Warns if a user-defined procedure or module procedure has the same name as an intrinsic. You might need an explicit interface, or anEXTERNALorINTRINSICdeclaration, so later calls resolve to the procedure you actually wanted. Implied by-Wall.-Wuse-without-onlyโ ๐ซฃ Warns if aUSEstatement has noONLYqualifier, because then it quietly and implicitly imports all public entities of the used module.-Wunused-dummy-argumentโ ๐งน Warns about unused dummy arguments. Implied by-Wall.-Wunused-parameterโ ๐ Plot twist: this one is not the same as gcc's version! gfortran's implementation doesn't warn about unused dummy arguments (that's-Wunused-dummy-argument). Instead, it warns about unusedPARAMETERvalues. It's implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commonsโ ๐งฉ By default, gfortran warns about any time variables get padded for proper alignment inside aCOMMONblock. You can silence it 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 code for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature may hurt performance. If the array is already allocated with the correct shape, try a whole-array array-spec like(:,:,:)on the left-hand side to skip the reallocation check. The warning can show up even when the compiler would optimize those 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 any allocatable variable, including scalars and derived types.-Wcompare-realsโ โ๏ธ Warns when you compare real or complex types for equality or inequality. Implied by-Wextra.-Wtarget-lifetimeโ โณ Warns if the pointer in a pointer assignment might outlive its target. Implied by-Wall.-Wzerotripโ 0๏ธโฃ 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 if the compiler can't prove the statement actually runs. Something like this:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
Implied by -Wextra.
-Werrorโ ๐จ Turns all warnings into errors, so no warning gets to slide.
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 has been translated into internal representation. It's mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may also cause 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 may change between releases, and it may also cause internal compiler errors for features that were only recently added.-fdump-parse-treeโ ๐๏ธ Outputs the internal parse tree after the source program has been translated into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may cause internal compiler errors for features that were only recently added. This option is deprecated, so use-fdump-fortran-originalinstead ๐-fdebug-aux-varsโ ๐ Renames the internal variables created by the gfortran front end and makes them accessible to a debugger. Their names start with upper-case letters followed by an underscore. It's handy for debugging the compiler's code generation together with-fdump-tree-original, and for debugging the executable program by using-gor-ggdb3.-fdump-fortran-globalโ ๐ Outputs a list of the global identifiers after translating into middle-end representation. Mostly useful for debugging the GNU Fortran compiler itself. The output may change between releases, and it may also cause 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 is sent and the program gets aborted, producing a core file that's useful for debugging.listis a (possibly empty) comma-separated list of these exceptions:invalid(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 operation)denormal(operation performed on a denormal value)
The first five correspond to 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 like x86.
The first three exceptions (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 you use -ffpe-trap more than once on the command line, the lists get joined. So -ffpe-trap=list1 followed by -ffpe-trap=list2 is the same as -ffpe-trap=list1,list2.
Once an exception is enabled, it can't be disabled. There's no negative form, so choose wisely! ๐ โโ๏ธ
Many, if not most, floating point operations lose some 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_UNITwhen you invokeSTOPorERROR STOP.listcan benone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (See-ffpe-trapfor what each one means.)
If you use this option 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 that have the action core), the Fortran runtime library tries to print a backtrace of the error.-fno-backtraceturns that backtrace generation off. This option 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, and also the#includedirective of thecpppreprocessor.
Also note that -I and INCLUDE act pretty much the same way -I does with #include in the cpp preprocessor ๐ง, when it comes to looking for header.gcc files and other stuff like that.
This path is also used to search for .mod files when previously compiled modules are needed by a USE statement ๐ฆ
-Jdirโ This tells the compiler where to put.modfiles for compiled modules ๐๏ธ It also gets added to the list of directories that aUSEstatement searches. The default is the current directory.-fintrinsic-modules-path dirโ Use this if your pre-compiled intrinsic modules aren't in the default spot the compiler expects ๐
โจ Influencing the linking step โจ
These options only matter when the compiler links object files into an executable output file ๐ If the compiler isn't doing a link step, they're totally meaningless ๐
-static-libgfortranโ On systems that ship libgfortran as both a shared and a static library, this forces the static version ๐ช If no shared version of libgfortran got built when the compiler was configured, this option does nothing.
๐ธ Influencing runtime behavior ๐ธ
These options change how programs compiled with GNU Fortran behave at runtime ๐
-fconvert=conversionโ This sets how data is represented in unformatted files ๐ The valid values forconversionare:nativeโ the defaultswapโ swap between big- and little-endianbig-endianโ use big-endian representation for unformatted fileslittle-endianโ use little-endian representation for unformatted files
This option 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 you set with -fconvert.
-frecord-marker=lengthโ This sets the length of record markers for unformatted files ๐ฆ The valid values forlengthare4and8, and the default is4. Heads up, this is different from older gfortran versions, which defaulted to8on most systems. If you want to read or write files that are compatible with earlier gfortran versions, use-frecord-marker=8๐ซถ-fmax-subrecord-length=lengthโ This sets the max length for a subrecord ๐ง The biggest value you can use 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, floating point numbers with a value of zero but the sign bit set get written as negative numbers in formatted output, and they're treated as negative in 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 counts zero as a positive number in theSIGNintrinsic, 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 come in positive and negative forms, where the negative form of -ffoo is -fno-foo ๐ Below, only one form is listed, the one that isn't the default. You can figure out the other form by removing no- or adding it.
-fno-automaticโ This treats each program unit (except those marked asRECURSIVE) like theSAVEstatement was specified for every local variable and array referenced in it ๐ซง It doesn't affect common blocks. Some Fortran compilers call this option-staticor-save. The default, which is-fautomatic, uses the stack for local variables smaller than the value given by-fmax-stack-var-size. If you want no static memory at all, use the option-frecursive.
Local variables or arrays with an explicit SAVE attribute get silently ignored unless you add the -pedantic option ๐
-ff2cโ This generates code that's designed to be compatible with code made by g77 and f2c ๐
The calling conventions g77 uses (originally from f2c) make functions that return default REAL actually return the C type double. Functions that return COMPLEX return 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 the way GNU C would: 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 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 changing the names of entities in your Fortran source file by adding underscores to them ๐ โโ๏ธ
With -funderscoring in effect, GNU Fortran adds one underscore to external names that don't have any underscores already. It does this so the code plays nicely with lots of UNIX Fortran compilers ๐ค
Caution: GNU Fortran's default behavior is incompatible with f2c and g77. If you want object files made by GNU Fortran to be compatible with object code made by those tools, please use the -ff2c option ๐ซถ
Using -fno-underscoring isn't recommended unless you're experimenting with stuff like fitting GNU Fortran into existing system environments (think existing libraries, tools, and so on) ๐งช
Here's an example. Say j() and max_count() are external functions, while my_var and lvar are local variables. With -funderscoring, 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 call user-defined names directly while debugging and when you're interfacing GNU Fortran code with other languages ๐ท
Just because the names match doesn't mean the interface GNU Fortran uses for an external name matches the interface another language uses for that same name ๐ค Getting code from GNU Fortran to link with code from some other compiler (using this or any other method) can be just a small part of the whole solution. Getting both compilers' output to agree on things other than naming can take a ton of 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 clash with a name in a system library. That can make unresolved-reference bugs really hard to find. They might happen at program run time and only show up as buggy behavior while the program runs ๐ต
In future versions of GNU Fortran, the plan is to improve naming and linking so debugging always uses the names as they appear in the source, even if the linker sees mangled names that stop 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 already have underscores, and one underscore to external names that don't. 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, and it's implied by the -ff2c option.
Without this option, an external name like MAX_COUNT gets implemented as a reference to the link-time external symbol max_count_. With this option, the same name becomes a reference to max_count__ instead. That's required for compatibility with g77 and f2c, and -ff2c implies it ๐ฅ
-fcoarray=<keyword>โ This controls coarray support, and you pick one of these keywords ๐งnoneโ Disables coarray support. Using coarray declarations and image-control statements will give you a compile-time error. (Default)singleโ Single-image mode, which meansnum_images()is always one ๐ฑlibโ Library-based coarray parallelization. A suitable GNU Fortran coarray library needs to be linked in ๐
-fcheck=<keyword>โ This turns on the generation of run-time checks. The argument is a comma-delimited list of the keywords below โ Puttingno-in front of a check turns it off, if an earlier specification turned it on.allโ Enables all run-time tests of-fcheck๐array-tempsโ Pings you at run time whenever passing an actual argument forced a temporary array to get made ๐งพ That info can be really handy for optimization, since you can use it to avoid those temporaries.- Heads up: this warning only prints once per location.
bitsโ Turns on run-time checks for invalid arguments to the bit manipulation intrinsics ๐งฎboundsโ Turns on 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 match for character array constructors that don't have an explicit typespec.- Some checks need
-fcheck=boundsto be set when the main program is compiled ๐ - Note: in the future this might also include other forms of checking, like checking substring references ๐ฎ
- Some checks need
doโ Turns on run-time checks for invalid modification of loop iteration variables ๐
memโ ๐ง turns on run-time checks for memory allocation. Heads up, bestie: this doesn't cover explicit allocations made with theALLOCATEstatement, because those are always checked anyway ๐pointerโ ๐ turns on run-time checks for pointers and allocatables โจrecursionโ ๐ turns on 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 gets switched off if you use it together with both-frecursiveand-fopenmp๐
Example time ๐ Say you've got a file called foo.f90, and you run:
gfortran -fcheck=all,no-array-temps foo.f90
That compiles the file with all the checks enabled as described above, except the warnings for generated array temporaries ๐
-fbounds-checkโ ๐๏ธ old-school name, and it's just a deprecated alias for-fcheck=bounds.-ftail-call-workaround,-ftail-call-workaround=nโ ๐ฉน okay so some C interfaces to Fortran code are rude and skip the hidden character length arguments as described in. That can cause crashes, because pushing arguments for tail calls can overflow the stack ๐ญ
This option is a band-aid for existing binary packages. It turns off tail call optimization for gfortran procedures with character arguments:
- With
-ftail-call-workaround=2, tail call optimization is disabled in all gfortran procedures with character arguments. - With
-ftail-call-workaround=1or plain-ftail-call-workaround, it's only disabled in gfortran procedures with character arguments that call implicitly prototyped procedures.
Caution: using this option can lead to problems, including crashes due to insufficient stack space ๐
It is very strongly recommended to fix the code in question ๐ซถ The -fc-prototypes-external option can generate prototypes that conform to gfortran's ABI, so you can include them in your source code.
Support for this option will likely be withdrawn in a future release of gfortran ๐
To turn it off, use -fno-tail-call-workaround or the equivalent -ftail-call-workaround=0. The current default is -ftail-call-workaround, but that's going to change in future releases ๐ธ
-fcheck-array-temporariesโ ๐๏ธ deprecated alias for-fcheck=array-temps.-fmax-array-constructor=nโ ๐ raises the upper limit allowed in array constructors. The code below needs this option so it can expand the array at compile time ๐
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
Caution: this option can lead to long compile times and excessively large object files ๐
The default value for n is 65535.
-fmax-stack-var-size=nโ ๐ฅ sets the size in bytes of the biggest array that gets put on the stack. If an array goes over that size, static memory is used instead (except in procedures marked asRECURSIVE). To allow recursive procedures that don't have aRECURSIVEattribute, or for parallel programs, use-frecursive. To never use the stack, use-fno-automatic๐ง
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 behaviour โจ
The default value for n is 65536.
-fstack-arraysโ ๐ฅก this puts all arrays of unknown size and all array temporaries onto stack memory. If your program uses really big 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 together as possible. Code compiled with this option 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 one's 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 might have to be packed (put into contiguous memory). Here's an example, the call tofooin:
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. That allows for more optimization, but the code gets bigger ๐
-finline-arg-packing is implied by any of the -O options, except when optimizing for size with -Os. If the code has a very large number of arguments that need packing, the code size and compile time can get excessive. If that happens, it might be better to disable this option ๐ You can find instances of packing by using -Warray-temporaries.
-fexternal-blasโ ๐งฎ makes gfortran call BLAS functions for some matrix operations likeMATMUL, instead of using its own algorithms, as long as the matrices involved are larger than a given limit (see-fblas-matmul-limit). This can be a win if an optimized vendor BLAS library is available ๐ฅ The BLAS library has to be specified at link time.-fblas-matmul-limit=nโ ๐ only matters when-fexternal-blasis in effect. Matrix multiplications with a size larger than (or equal to)nare done by calls to BLAS functions, and the rest are handled by gfortran's internal algorithms. If the matrices aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices ๐ฆ
The default value for n is 30.
-finline-matmul-limit=nโ ๐ช when front-end optimization is active, some calls to theMATMULintrinsic function get inlined. This can increase code size if the size of the matrix can't be figured out at compile time, since code for both cases gets generated. Setting-finline-matmul-limit=0turns off 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 for n is 30. The -fblas-matmul-limit option can be used to change this value ๐
-frecursiveโ ๐ allows indirect recursion by forcing all local arrays to be allocated on the stack. You can't use this flag 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โ ๐ซง this whole family handles initialization of local variables, so nothing starts out as random garbage.
-finit-local-zero tells the compiler to set local INTEGER, REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER variables to a string of null bytes. If you want finer-grained control, there are the -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real and imaginary parts of local COMPLEX variables), -finit-logical=<true|false>, and -finit-character=n options. Here n is an ASCII character value for the character one ๐
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 as described above 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 a quiet NaN, and trapping needs to be enabled (e.g. via -ffpe-trap) ๐ฅ
The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. That value is then assigned to the integer variables in the Fortran code, which might wrap around if the value is too large for the kind ๐ญ
Finally, enabling any of the -finit-* options will silence 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 disable the automatic alignment. Use the same form of this option for all files that share aCOMMONblock ๐ซถ To avoid potential alignment issues inCOMMONblocks, it's recommended to order objects from largest to smallest ๐-fno-protect-parens: okay so by default the compiler respects your parentheses at every optimization level, so it never re-associates anything ๐ Add-fno-protect-parensand it's allowed to reorderREALandCOMPLEXexpressions for faster code โจ Heads up, bestie: that re-association also needs-fno-signed-zerosand-fno-trapping-mathin effect ๐ Parens protection is on by default, unless you pass-Ofast๐ฅ-frealloc-lhs: an allocatable left-hand side of an intrinsic assignment gets (re)allocated automatically if it's unallocated or has a different shape ๐ฆ It's on by default except when-std=f95is given. See also-Wrealloc-lhs๐-faggressive-function-elimination: functions with identical argument lists get eliminated within statements, even if they aren't markedPURE๐ง So something like this only makes a single call tof:
a = f(b,c) + f(b,c)
This only works if -ffrontend-optimize is in effect ๐ซถ
-ffrontend-optimize: this one does front-end optimization by messing around with parts of the Fortran parse tree ๐ธ It's enabled by default by any-Ooption except-O0and-Og. The optimizations it turns on include:- inlining calls to
MATMUL, - getting rid 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 logical operators (
.AND.and.OR.).
- inlining calls to
If you want it gone, use -fno-frontend-optimize ๐
-ffrontend-loop-interchange: the front end tries to swap loops whenever it's worth it ๐ It's enabled by default by any-Ooption. Right now it only affectsFORALLandDO CONCURRENTstatements with several forall triplets ๐
โจ ENVIRONMENT โจ
gfortran doesn't read any environment variables of its own to control how it runs ๐ It only uses the ones that already affect gcc.
๐ BUGS ๐
Want to report a bug? Check out <file:///usr/share/doc/gcc-11/README.Bugs> for instructions ๐ซถ
โจ SEE ALSO โจ
gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1) and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb ๐
โจ AUTHOR โจ
For the contributors to GCC and GNU Fortran, check the Info entry for gfortran ๐งโ๐ป
โจ COPYRIGHT โจ
Copyright (c) 2004-2021 Free Software Foundation, Inc.
You're allowed to copy, distribute and/or modify this document 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 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! ๐ This version came from the gcc-11 build, last updated 2024-07-19, so you're fully caught up now ๐๐ฆ
๐ฆ where this page comes from
- ubuntu noble: gfortran-11-mips-linux-gnu 11.5.0-1ubuntu1~24.04cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms