GFORTRAN(1)
π GFORTRAN π
okay bestie, sit down, hydrate, because we're about to read the GNU Fortran compiler man page together and honestly? it's a lot but we're gonna slay it. this is section 1 of the GNU manual. the command is gfortran and she is the GNU Fortran compiler, no cap. π«Ά
β¨ SYNOPSIS β¨
here's the vibe, the whole shape of it:
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
lowkey important: only the most useful options are listed up there. the rest of them are literally below, so keep scrolling babe.
πΈ DESCRIPTION πΈ
so, gfortran? she supports all the options that gcc supports. iconic behavior. but this manual is only documenting the options that are specific to GNU Fortran β we're not re-doing gcc's whole thing, that's a different girl.
every GCC option and every GNU Fortran option gets accepted by both gfortran and gcc β plus any other drivers that were built at the same time, like g++. why? because adding GNU Fortran to the GCC distribution means all the relevant drivers accept GNU Fortran options. it's giving "we're all one big family" fr fr. π
in some cases, options come in positive and negative forms β the negative form of -ffoo would be -fno-foo. and this manual only documents one of the two forms: whichever one is not the default. that's the rule, that's the law, periodt.
π OPTIONS π
here's the summary of every option that's specific to GNU Fortran, grouped by type. the actual explanations live in the sections after this one, so don't panic.
π 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 -static-libquadmath
π§ Runtime Options
-fconvert=conversion -fmax-subrecord-length=length
-frecord-marker=length -fsign-zero
πΈ Interoperability Options
-fc-prototypes -fc-prototypes-external
π₯ Code Generation Options
-faggressive-function-elimination -fblas-matmul-limit=n
-fbounds-check -ftail-call-workaround -ftail-call-workaround=n
-fcheck-array-temporaries
-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>
-fcoarray=<none|single|lib> -fexternal-blas -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 are the options that control the details of the Fortran dialect the compiler is willing to accept. yes, she's picky. we love that for her.
-ffree-form-ffixed-formβ these two set the layout used by the source file. free form layout was introduced in Fortran 90. fixed form was traditionally used in older Fortran programs. when neither option is specified, the source form gets determined by the file extension. cute, right?-fall-intrinsicsβ this option causes all intrinsic procedures (including the GNU-specific extensions) to be accepted. useful with-std=to force standard-compliance but still get access to the full range of intrinsics available withgfortran. as a consequence,-Wintrinsics-stdwill be ignored and no user-defined procedure with the same name as any intrinsic will be called except when it is explicitly declaredEXTERNAL.-fallow-argument-mismatchβ some code contains calls to external procedures with mismatches between the calls and the procedure definition, or with mismatches between different calls. such code is non-conforming and will usually be flagged with an error. this option degrades the error to a warning, which can only be disabled by disabling all warnings via-w. only a single occurrence per argument is flagged by this warning.-fallow-argument-mismatchis implied by-std=legacy.
bestie, using this option is strongly discouraged. it is possible to provide standard-conforming code which allows different types of arguments by using an explicit interface and TYPE(*).
-fallow-invalid-bozβ a BOZ literal constant can occur in a limited number of contexts in standard conforming Fortran. this option degrades an error condition to a warning, and allows a BOZ literal constant to appear where the Fortran standard would otherwise prohibit its use.-fd-lines-as-code-fd-lines-as-commentsβ enable special treatment for lines beginning with"d"or"D"in fixed form sources. if the-fd-lines-as-codeoption is given, they're treated as if the first column contained a blank. if the-fd-lines-as-commentsoption is given, they're treated as comment lines.-fdecβ DEC compatibility mode. enables extensions and other features that mimic the default behavior of older compilers (such as DEC). these features are non-standard and should be avoided at all costs. for details on GNU Fortran's implementation of these extensions, see 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 -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β enable the use of character literals in assignments and"DATA"statements for non-character variables.-fdec-structureβ enable DEC"STRUCTURE"and"RECORD"as well as"UNION","MAP", and dot (.) as a member separator (in addition to%). this is provided for compatibility only; Fortran 90 derived types should be used instead where possible.-fdec-intrinsic-intsβ enable 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β enable legacy math intrinsics such as COTAN and degree-valued trigonometric functions (e.g. TAND, ATAND, etc...) for compatability with older code.-fdec-staticβ enable DEC-style STATIC and AUTOMATIC attributes to explicitly specify the storage of variables and other objects.-fdec-includeβ enable parsing of INCLUDE as a statement in addition to parsing it as INCLUDE line. when parsed as INCLUDE statement, INCLUDE does not have to be on a single line and can use line continuations.-fdec-format-defaultsβ enable format specifiers F, G and I to be used without width specifiers; default widths will be used instead.-fdec-blank-format-itemβ enable a blank format item at the end of a format specification, i.e. nothing following the final comma.-fdollar-okβ allow$as a valid non-first character in a symbol name. symbols that start with$are rejected, since it's unclear which rules to apply to implicit typing as different vendors implement different rules. using$in"IMPLICIT"statements is also rejected.-fbackslashβ change the interpretation of backslashes in string literals from a single backslash character to "C-style" escape characters. the following combinations are expanded"\a","\b","\f","\n","\r","\t","\v","\\", and"\0"to the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. additionally,"\x"nn,"\u"nnnnand"\U"nnnnnnnn(where each n is a hexadecimal digit) are translated into the Unicode characters corresponding to the specified code points. all other combinations of a character preceded by\are unexpanded.-fmodule-privateβ set the default accessibility of module entities to"PRIVATE". use-associated entities will not be accessible unless they're explicitly declared as"PUBLIC".-ffixed-line-length-nβ set the column after which characters are ignored in typical fixed-form lines in the source file, and, unless"-fno-pad-source", 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 that the entire line is meaningful and that continued character constants never have implicit spaces appended to them 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 have spaces assumed (as if padded to that length) after the ends of short fixed-form lines. this is not done either if-ffixed-line-length-0,-ffixed-line-length-noneor if the-fno-pad-sourceoption is used. with any of those options, continued character constants never have implicit spaces appended to them to fill out the line.
more parts are coming bestie, don't go anywhere π
-ffree-line-length-nβ bestie, this one sets the column after which characters get ignored in your typical free-form source lines. Default is132. Andncan benone, which means the whole entire line is meaningful, no cap. Also-ffree-line-length-0means the exact same thing as-ffree-line-length-none. β¨-fmax-identifier-length=nβ sets the max allowed identifier length. The typical values are31(Fortran 95) and63(Fortran 2003 and later). π-fimplicit-noneβ says no implicit typing allowed, unless an explicitIMPLICITstatement overrides it. It's literally the equivalent of addingimplicit noneto the start of every procedure. iconic.-fcray-pointerβ turns on the Cray pointer extension, which gives you C-like pointer functionality. π¦-fopenaccβ enables the OpenACC extensions. This includes OpenACC!$accdirectives in free form andc$acc,*$accand!$accdirectives in fixed form,!$conditional compilation sentinels in free form andc$,*$and!$sentinels in fixed form, and when linking it arranges for the OpenACC runtime library to be linked in. π-fopenmpβ enables the OpenMP extensions. This includes OpenMP!$ompdirectives in free form andc$omp,*$ompand!$ompdirectives in fixed form,!$conditional compilation sentinels in free form andc$,*$and!$sentinels in fixed form, and when linking it arranges for the OpenMP runtime library to be linked in. Also, heads up: the option-fopenmpimplies-frecursive. π₯-fno-range-checkβ disables range checking on results of simplification of constant expressions during compilation. For example, GNU Fortran will give an error at compile time when simplifyinga = 1. / 0. With this option, no error will be given andawill be assigned the value+Infinity. If an expression evaluates to a value outside of the relevant range of [-HUGE():HUGE()], then the expression will be replaced by-Infor+Infas appropriate. Similarly,DATA i/Z'FFFFFFFF'/will result in an integer overflow on most systems, but with -fno-range-check the value will "wrap around" andiwill be initialized to -1 instead. π-fdefault-integer-8β sets the default integer and logical types to an 8 byte wide type. This option also affects the kind of integer constants like 42. 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 option also affects the kind of non-double real constants like 1.0. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-8,DOUBLE 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 an 10 byte wide type. This option also affects the kind of non-double real constants like 1.0. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along with-fdefault-real-10,DOUBLE 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 an 16 byte wide type. This option also affects the kind of non-double real constants like 1.0. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along with-fdefault-real-16,DOUBLE 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. Do nothing if this is already the default. This option prevents -fdefault-real-8, -fdefault-real-10, and -fdefault-real-16, from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes. π-finteger-4-integer-8β promotes all INTEGER(KIND=4) entities to an INTEGER(KIND=8) entities. IfKIND=8is unavailable, then an error will be issued. This option should be used with care and 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. Inspection of 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β promote all REAL(KIND=M) entities to REAL(KIND=N) entities. If REAL(KIND=N) is unavailable, then an error will be issued. The-freal-4-flags also affect the default real kind and the-freal-8-flags also the double-precision real kind. All other real-kind types are unaffected by this option. The promotion is also applied to real literal constants of default and double-precision kind and 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 inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O and calls to intrinsic procedures when passing a value to thekind=dummy argument. Inspection of the intermediate representation of the translated Fortran code, produced by -fdump-fortran-original or -fdump-tree-original, is suggested. π-std=stdβ specify the standard to which the program is expected to conform, which may be one off95,f2003,f2008,f2018,gnu, orlegacy. The default value forstdisgnu, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran, although warnings will be given for obsolete extensions not recommended for use in new code. Thelegacyvalue is equivalent but without the warnings for obsolete extensions, and 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 are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards. The deprecated option -std=f2008ts acts as an alias for -std=f2018. It is only present for backwards compatibility with earlier gfortran versions and should not be used any more. π-ftest-forall-tempβ enhance test coverage by forcing most forall assignments to use temporary. π§
β¨ Enable and customize preprocessing β¨
Okay so many Fortran compilers including GNU Fortran allow passing the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) to allow for conditional compilation. In the case of GNU Fortran, this is the GNU C Preprocessor in the traditional mode. On systems with case-preserving file names, the preprocessor is automatically invoked if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. To manually invoke the preprocessor on any file, use -cpp, to disable preprocessing on files where the preprocessor is run automatically, use -nocpp. π
If a preprocessed file includes another file with the Fortran INCLUDE statement, the included file is not preprocessed. To preprocess included files, use the equivalent preprocessor statement #include. π¦
If GNU Fortran invokes the preprocessor, __GFORTRAN__ is defined. The macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ can be used to determine the version of the compiler. See Top,,Overview,cpp,The C Preprocessor for details. π
GNU Fortran supports a number of INTEGER and REAL kind types in additional to the kind types required by the Fortran standard. The availability of any given kind type is architecture dependent. The following pre-defined preprocessor macros can be used to conditionally include code for these additional kind types: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__. π
While CPP is the de-facto standard for preprocessing Fortran code, Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional Compilation, which is not widely used and not directly supported by the GNU Fortran compiler. You can use the program coco to preprocess such files (http://www.daniellnagle.com/coco.html). π
The following options control preprocessing of Fortran code:
-cpp,-nocppβ enable preprocessing. The preprocessor is automatically invoked if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08. Use this option to manually enable preprocessing of any kind of Fortran file.
To disable preprocessing of files with any of the above listed extensions, use the negative form: -nocpp.
The preprocessor is run in traditional mode. Any restrictions of the file-format, especially the limits on line length, apply for 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, generate a list of#definedirectives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no file foo.f90, the command
touch foo.f90; gfortran -cpp -E -dM foo.f90
will show all the predefined macros. π
-dDβ basically-dM's cousin, but it does two things differently: it does NOT include 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 the macro names, not their expansions. Just the names, bestie. π-dUβ like-dDexcept that only macros that are expanded, or whose definedness is tested in preprocessor directives, get output; the output is delayed until the use or test of the macro; and'#undef'directives are also output for macros tested but undefined at the time. π-dIβ outputs'#include'directives 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 on, the preprocessor will emit, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC will use this directory, when it is 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"#line"directives are emitted whatsoever. π-idirafterdir β search dir for include files, but do it after all directories specified with-Iand the standard system directories have been exhausted. dir is treated as a system include directory. If dir begins with"=", then the"="will be replaced by the sysroot prefix; see--sysrootand-isysroot. π¦-imultilibdir β use dir as a subdirectory of the directory containing target-specific C++ headers. π-iprefixprefix β specify prefix as the prefix for subsequent-iwithprefixoptions. If the prefix represents a directory, you should include the final'/'. π-isysrootdir β this option is like the--sysrootoption, but it applies only to header files. See the--sysrootoption for more info. β¨-iquotedir β search dir only for header files requested with"#include "file""; they are not searched for"#include <file>", and this happens before all directories specified by-Iand before the standard system directories. If dir begins with"=", then the"="will be replaced by the sysroot prefix; see--sysrootand-isysroot. πΈ-isystemdir β search dir for header files, after all directories specified by-Ibut before the standard system directories. Mark it as a system directory, so it gets the same special treatment as is applied to the standard system directories. If dir begins with"=", then the"="will be replaced by the sysroot prefix; see--sysrootand-isysroot. π-nostdincβ do not search the standard system directories for header files. Only the directories you've specified with-Ioptions (and the directory of the current file, if appropriate) get searched. π-undefβ do not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined. π«Ά-Apredicate=answerβ make an assertion with the predicate predicate and answer answer. This form is preferred to the older form-Apredicate(answer), which is still supported, because it does not use shell special characters. π-A-predicate=answerβ cancel an assertion with the predicate predicate and answer answer. π-Cβ do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive.
You should be prepared for side effects when using -C; it causes the preprocessor to treat comments as tokens in their own right. For example, comments appearing at the start of what would be a directive line have the effect of turning 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β do not discard comments, including during macro expansion. This is like-C, except that comments contained within macros are also passed through to the output file where the macro is expanded.
In addition to the side-effects of the -C option, the -CC option causes all C++-style comments inside a macro to be converted to C-style comments. This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line. The -CC option is generally used to support lint comments. π
Warning: this currently handles C- and C++-Style comments only. The preprocessor does not yet recognize Fortran-style comments.
-Dnameβ predefine name as a macro, with definition1. β¨-Dname=definitionβ the contents of definition are tokenized and processed as if they appeared during translation phase three in a'#define'directive. In particular, the definition will be truncated by embedded newline characters. π³
If you're invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax. π
If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you will need to quote the option. With sh and csh, "-D'name(args...)=definition'" works. π
-D and -U options are processed in the order they are given on the command line. All -imacros file and -include file options are processed after all -D and -U options.
-Hβ print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the'#include'stack it is. π-Pβ inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers. π§-Unameβ cancel any previous definition of name, either built in or provided with a-Doption. π
π€ Options to request or suppress errors and warnings π€
Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler will continue to process the program in an attempt to report further errors to aid in debugging, but will not produce any compiled output. π
Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there is likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. π«Ά
You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default. π
These options control the amount and kinds of errors and warnings produced by GNU Fortran: β¨
- *
-fmax-errors=n* β limits the maximum number of error messages to n, at which point GNU Fortran bails out rather than attempting to continue processing the source code. If n is0, there is no limit on the number of error messages produced. π -fsyntax-onlyβ check the code for syntax errors, but do not actually compile it. This will generate module files for each module present in the code, but no other output file. π-Wpedantic,-pedanticβ issue warnings for uses of extensions to Fortran.-pedanticalso applies to C-language constructs where they occur in GNU Fortran source files, such as use of\ein a character constant within a directive like"#include". π¬
Valid Fortran programs should compile properly with or without this option. However, without this option, certain GNU extensions and traditional Fortran features are supported as well. With this option, many of them are rejected. π«
Some users try to use -pedantic to check programs for conformance. They soon find that it does not do quite what they want---it finds some nonstandard practices, but not all. However, improvements to GNU Fortran in this area are welcome. π
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018. π
-pedantic-errorsβ like-pedantic, except that errors are produced rather than warnings. π€-Wallβ enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. This currently includes-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop. ππ₯-Waliasingβ warn 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β warn about a missing ampersand in continued character constants. The warning is given with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008and-std=f2018. Note: with no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that initiated the continuation. πΈ-Warray-temporariesβ warn about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries. π¦-Wc-binding-typeβ bestie, this one's like a vibe check for C interoperability π it warns you if a variable might not be C interoperable. Specifically, it flags when a variable's been declared with an intrinsic type using the default kind instead of a kind parameter that's actually defined for C interoperability in the intrinsicISO_C_Bindingmodule. Oh, and-Wallimplies this one.-Wcharacter-truncationβ warns you when a character assignment is gonna truncate the string you're assigning. not ideal, fr fr π-Wline-truncationβ warns when a source code line is gonna get truncated.-Wallimplies this. And for free-form source code, the default is-Werror=line-truncation, so truncations get reported as errors, periodt.-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. Lowkey important: this option does not imply-Wconversion.-Wextraβ turns on a bunch of warning options for language features that might be problematic. Currently this includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscriptπ«Ά-Wfrontend-loop-interchangeβ warns when you're using-ffrontend-loop-interchangeto do loop interchanges.-Wimplicit-interfaceβ warns if a procedure gets called without an explicit interface. Heads up tho: it 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 been declared asEXTERNAL.-Winteger-divisionβ warns if a constant integer division truncates its result. Like,3/5evaluates to0. yeah. π-Wintrinsics-stdβ warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (the one from-std) and treats it as anEXTERNALprocedure because of that. You can use-fall-intrinsicsto never trigger this behavior and always link to the intrinsic regardless of the selected standard. slay π-Wno-overwrite-recursiveβ tells it not to warn when-fno-automaticis used together with-frecursive. Real talk: recursion will be broken if the relevant local variables don't have theAUTOMATICattribute explicitly declared. You can use this option to suppress the warning when you know recursion isn't broken. Super useful for build environments that use-Werror. π-Wreal-q-constantβ produces a warning if a real-literal-constant contains aqexponent-letter.-Wsurprisingβ produces a warning when "suspicious" code constructs show up. Like, technically legal, but usually it means somebody made a mistake. π©
Right now it produces a warning under these circumstances:
- 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 enabled, this is an error. - A
CHARACTERvariable is declared with negative length. - With
-fopenmp, for fixed-form source code, when anomxvendor-extension sentinel is encountered. (The equivalentompx, used in free-form source code, is diagnosed by default.)
-Wtabsβ okay so by default, tabs are accepted as whitespace, but tabs are not members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported.-Wtabsmakes a warning get issued if a tab is encountered. Note:-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall. β¨-Wundefined-do-loopβ warns if aDOloop with step either1or-1yields an underflow or an overflow during iteration of an induction variable of the loop. Implied by-Wall.-Wunderflowβ produces a warning when numerical constant expressions are encountered that yield an UNDERFLOW during compilation. Enabled by default.-Wintrinsic-shadowβ warns if a user-defined procedure or module procedure has the same name as an intrinsic. In this case, an explicit interface orEXTERNALorINTRINSICdeclaration might be needed to get calls later resolved to the desired intrinsic/procedure. Implied by-Wall.-Wuse-without-onlyβ warns if aUSEstatement has noONLYqualifier and thus implicitly imports all public entities of the used module. π¬-Wunused-dummy-argumentβ warns about unused dummy arguments. Implied by-Wall.-Wunused-parameterβ plot twist: unlike gcc's meaning of-Wunused-parameter, gfortran's implementation of this option does not warn about unused dummy arguments (that's what-Wunused-dummy-argumentis for, bestie) β it warns about unusedPARAMETERvalues instead.-Wunused-parameteris implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commonsβ by default, gfortran warns about any occasion of variables being padded for proper alignment inside aCOMMONblock. You can turn this off with-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationβ warns if any calls to impure functions get eliminated by the optimizations enabled by the-ffrontend-optimizeoption. 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 reduce performance π If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g.(:,:,:)) for the variable on the left-hand side to prevent the reallocation check. Note that in some cases the warning is shown even if the compiler will optimize reallocation checks away. For instance, when the right-hand side contains the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allβ warns when the compiler inserts code for allocation or reallocation of an allocatable variable; this includes scalars and derived types.-Wcompare-realsβ warns when comparing real or complex types for equality or inequality. Implied by-Wextra.-Wtarget-lifetimeβ warns if the pointer in a pointer assignment might be longer than its target. Implied by-Wall.-Wzerotripβ warns if aDOloop is known to execute zero times at compile time. Implied by-Wall.-Wdo-subscriptβ warns if an array subscript inside aDOloop could lead to an out-of-bounds access, even if the compiler can't prove that the statement is actually executed. Cases like this:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
This option is implied by -Wextra.
-Werrorβ turns all warnings into errors. every single one. no mercy π
Some of these have no effect when compiling programs written in Fortran.
β¨ Options for debugging your program or GNU Fortran β¨
GNU Fortran has a whole lil collection of special options that are used for debugging either your program or the GNU Fortran compiler itself. π¦
-fdump-fortran-originalβ outputs the internal parse tree after translating the source program into internal representation. This one's mostly useful for debugging the GNU Fortran compiler itself. Just so you know, the output generated by this option might change between releases. It may also generate internal compiler errors for features which have only recently been added. π«-fdump-fortran-optimizedβ outputs the parse tree after front-end optimization. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added.-fdump-parse-treeβ outputs the internal parse tree after translating the source program into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added. Heads up: this option is deprecated β use-fdump-fortran-originalinstead.-fdebug-aux-varsβ renames internal variables created by the gfortran front end and makes them accessible to a debugger. The names of the internal variables then start with upper-case letters followed by an underscore. This option is useful for debugging the compiler's code generation together with-fdump-tree-original, and for enabling debugging of 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 generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added.-ffpe-trap=listβ specifies a list of floating point exception traps to enable. On most systems, if a floating point exception occurs and the trap for that exception is enabled, aSIGFPEsignal will be sent and the program being run will be aborted, producing a core file useful for debugging. πΈ
list is a (possibly empty) comma-separated list of the following exceptions: invalid (invalid floating point operation, such as SQRT(-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), and denormal (operation performed on a denormal value).
The first five exceptions correspond to the five IEEE 754 exceptions, whereas the last one (denormal) is not part of the IEEE 754 standard but is available on some common architectures such as x86.
The first three exceptions β invalid, zero, and overflow β are lowkey the drama queens of floating point. They usually mean something has gone <em>seriously</em> wrong, so unless your program is built different and actually has a plan for handling them, turning on traps for those three is genuinely a good idea. π
If you pass this option more than once on the command line, the lists just get glued together: "ffpe-trap="list1 "ffpe-trap="list2 hits the same as "ffpe-trap="list1,list2.
Heads up bestie: once an exception is enabled, it cannot be disabled. There is no negative form. It's giving no take-backs. π
Also, like, most floating point operations lose a little precision from rounding β many, if not most β so "ffpe-trap=inexact" is probably not the vibe you're looking for in practice.
By default? No exception traps are enabled. Chill by default. β¨
-ffpe-summary=listβ give it a list of floating-point exceptions whose flag status gets printed to"ERROR_UNIT"whenever you invoke"STOP"or"ERROR STOP". The list can benone,all, or a comma-separated list of: invalid, zero, overflow, underflow, inexact, and denormal. (Peep-ffpe-trapfor what each exception actually means.)
If you use this option more than once, only the last one counts. No joining here, sorry. π
By default, you get a summary for all the exceptions except inexact. π
-fno-backtraceβ when a serious runtime error happens, or a deadly signal gets emitted (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals that have the actioncore), the Fortran runtime library tries to spit out a backtrace of the error."-fno-backtrace"turns that backtrace generation off. Ngl this option only has influence when you're compiling the Fortran main program.
πΈ Options for directory search πΈ
These options control how GNU Fortran goes looking for files specified by the "INCLUDE" directive, and where it hunts down previously compiled modules. π
They also affect the search paths that cpp uses when it's preprocessing Fortran source.
-Idirβ these change how the"INCLUDE"directive gets interpreted (and also the"#include"directive of the cpp preprocessor, bestie).
Also note: the general behavior of -I and "INCLUDE" is pretty much the same as -I with "#include" in the cpp preprocessor, when it comes to looking for header.gcc files and other such things.
This path also gets used to search for .mod files when previously compiled modules are required by a "USE" statement.
-Jdirβ this one says where to put.modfiles for compiled modules. It also gets added to the list of directories searched by a"USE"statement. π
The default is the current directory.
-fintrinsic-modules-path dirβ this specifies the location of pre-compiled intrinsic modules, for when they're not chilling in the default location the compiler expects. β¨
π₯ Influencing the linking step π₯
These options show up when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're meaningless. Periodt.
-static-libgfortranβ on systems that offerlibgfortranas both a shared and a static library, this option forces the static version to be used. If no shared version oflibgfortranwas built when the compiler was configured, this option has no effect. π-static-libquadmathβ same energy: on systems that offerlibquadmathas both a shared and a static library, this forces the static version. If no shared version oflibquadmathwas built when the compiler was configured, this option has no effect.
Please note: the libquadmath runtime library is licensed under the GNU Lesser General Public License (LGPL), and linking it statically introduces requirements when redistributing the resulting binaries. That's a real thing, don't skip it. π«Ά
π Influencing runtime behavior π
These options change how programs compiled with GNU Fortran behave at runtime.
-fconvert=conversionβ specifies the representation of data for unformatted files. Valid values for conversion on most systems are:nativeβ the default β¨swapβ swap between big- and little-endianbig-endianβ use big-endian representation for unformatted fileslittle-endianβ use little-endian representation for unformatted files
On POWER systems that support -mabi=ieeelongdouble, there are extra options, and you can combine them with others using commas. Those are:
-fconvert=r16_ieeeβ Use IEEE 128-bit format forREAL(KIND=16).-fconvert=r16_ibmβ Use IBM long double format forREAL(KIND=16).
This option only has an effect when used in the main program. The "CONVERT" specifier and the GFORTRAN_CONVERT_UNIT environment variable override the default set by -fconvert. π
-frecord-marker=lengthβ sets the length of record markers for unformatted files. Valid values for length are4and8. Default is4. This is different from previous versions of gfortran, which specified a default record marker length of8on most systems. If you want to read or write files compatible with earlier versions of gfortran, use-frecord-marker=8. π°οΈ-fmax-subrecord-length=lengthβ sets the maximum length for a subrecord. The maximum permitted value for length is2147483639, which is also the default. Only really useful for use by the gfortran testsuite. Fr fr, that's it.-fsign-zeroβ when enabled, floating point numbers of value zero with the sign bit set are written as negative numbers in formatted output, and treated as negative in the"SIGN"intrinsic.-fno-sign-zerodoes not print the negative sign of zero values (or values rounded to zero for I/O) and regards zero as a positive number in the"SIGN"intrinsic, for compatibility with Fortran 77. The default is-fsign-zero. π
π Options for code generation conventions π
These machine-independent options control the interface conventions used in code generation.
Most of them have both positive and negative forms β the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed, the one which is not the default. You can figure out the other form by either removing no- or adding it. Iykyk. β¨
-fno-automaticβ treats each program unit (except those marked asRECURSIVE) as if the"SAVE"statement were specified for every local variable and array referenced in it. Doesn't affect common blocks. (Some Fortran compilers provide this option under the name-staticor-save.) The default, which is-fautomatic, uses the stack for local variables smaller than the value given by-fmax-stack-var-size. Use the option-frecursiveto use no static memory.
Local variables or arrays having an explicit "SAVE" attribute are silently ignored unless the -pedantic option is added. π
-ff2cβ generates code designed to be compatible with code generated byg77andf2c.
The calling conventions used by g77 (originally implemented in f2c) require functions that return type default "REAL" to actually return the C type "double", and functions that return type "COMPLEX" to return the values via an extra argument in the calling sequence that points to where the return value should be stored. Under the default GNU calling conventions, such functions simply return their results as they would in GNU C β default "REAL" functions return the C type "float", and "COMPLEX" functions return the GNU C type "complex". Additionally, this option implies the -fsecond-underscore option, unless -fno-second-underscore is explicitly requested.
This does not affect the generation of code that interfaces with the libgfortran library.
Caution: it is not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions, because calling"COMPLEX"or default"REAL"functions between program parts which were compiled with different calling conventions will break at execution time. π
Caution: this will break code which passes intrinsic functions of type default"REAL"or"COMPLEX"as actual arguments, since the library implementations use the-fno-f2ccalling conventions. π
-fno-underscoringβ do not transform names of entities specified in the Fortran source file by appending underscores to them.
With -funderscoring in effect, GNU Fortran appends one underscore to external names. This is done to ensure compatibility with code produced by many UNIX Fortran compilers.
Caution: the default behavior of GNU Fortran is incompatible withf2candg77, so please use the-ff2coption if you want object files compiled with GNU Fortran to be compatible with object code created with these tools. π¨
Use of -fno-underscoring is not recommended unless you're experimenting with issues like integrating GNU Fortran into existing system environments (vis-Γ -vis existing libraries, tools, and so on).
For example, with -funderscoring, and assuming that j() and max_count() are external functions while "my_var" and "lvar" are local variables, a statement like
I = J() + MAX_COUNT (MY_VAR, LVAR)
is implemented as something akin to:
i = j_() + max_count_(&my_var, &lvar);
With -fno-underscoring, the same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
Use of -fno-underscoring allows direct specification of user-defined names while debugging and when interfacing GNU Fortran code with other languages. π¦
Note that just because the names match does not mean that the interface implemented by GNU Fortran for an external name matches the interface implemented by some other language for that same name. That is, getting code produced by GNU Fortran to link to code produced by some other compiler using this or any other method can be only a small part of the overall solution β getting the code generated by both compilers to agree on issues other than naming can require significant effort, and, unlike naming disagreements, linkers normally cannot detect disagreements in these other areas.
Also, note that with -fno-underscoring, the lack of appended underscores introduces the very real possibility that a user-defined external name will conflict with a name in a system library, which could make finding unresolved-reference bugs quite difficult in some cases β they might occur at program run time, and show up only as buggy behavior at run time. π
So like, future versions of GNU Fortran are manifesting better naming and linking so debugging always uses the names as they appear in the source β even if the linker sees mangled names to stop accidental linking between procedures with incompatible interfaces. Manifesting that fr fr.
-fsecond-underscoreβ bestie, by default GNU Fortran slaps an underscore onto external names. If you use this option, GNU Fortran appends two underscores to names that already have underscores, and one underscore to external names with no underscores. It also appends two underscores to internal names with underscores to avoid naming collisions with external names.
This option has no effect if -fno-underscoring is in effect. It is implied by the -ff2c option.
Otherwise, with this option, an external name such as MAX_COUNT is implemented as a reference to the link-time external symbol max_count__, instead of max_count_. This is required for compatibility with g77 and f2c, and is implied by use of the -ff2c option.
-fcoarray=<keyword>β okay so coarray vibes, pick your keyword:noneβ Disable coarray support; using coarray declarations and image-control statements will produce a compile-time error. (Default)singleβ Single-image mode, i.e.num_images()is always one.libβ Library-based coarray parallelization; a suitable GNU Fortran coarray library needs to be linked.
-fcheck=<keyword>β Enable the generation of run-time checks; the argument shall be a comma-delimited list of the following keywords. Prefixing a check withno-disables it if it was activated by a previous specification. It's giving safety net, but make it customizable.allβ Enable all run-time test of-fcheck.array-tempsβ Warns at run time when for passing an actual argument a temporary array had to be generated. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries.
Note: The warning is only printed once per location.
bitsβ Enable generation of run-time checks for invalid arguments to the bit manipulation intrinsics.boundsβ Enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds and ensures that all string lengths are equal for character array constructors without an explicit typespec. Some checks require that-fcheck=boundsis set for the compilation of the main program.
Note: In the future this may also include other forms of checking, e.g., checking substring references.
doβ Enable generation of run-time checks for invalid modification of loop iteration variables.memβ Enable generation of run-time checks for memory allocation.
Note: This option does not affect explicit allocations using the ALLOCATE statement, which will be always checked.
pointerβ Enable generation of run-time checks for pointers and allocatables.recursionβ Enable generation of run-time checks for recursively called subroutines and functions which are not marked as recursive. See also-frecursive.
Note: This check does not work for OpenMP programs and is disabled if used together with-frecursiveand-fopenmp.
Example: Assuming you have a file foo.f90, the command
gfortran -fcheck=all,no-array-temps foo.f90
will compile the file with all checks enabled as specified above except warnings for generated array temporaries.
-fbounds-checkβ Deprecated alias for-fcheck=bounds.-ftail-call-workaround-ftail-call-workaround=nβ Some C interfaces to Fortran codes violate the gfortran ABI by omitting the hidden character length arguments as described in β This can lead to crashes because pushing arguments for tail calls can overflow the stack.
To provide a workaround for existing binary packages, this option disables tail call optimization for gfortran procedures with character arguments. With -ftail-call-workaround=2 tail call optimization is disabled in all gfortran procedures with character arguments, with -ftail-call-workaround=1 or equivalent -ftail-call-workaround only in gfortran procedures with character arguments that call implicitly prototyped procedures.
Using this option can lead to problems including crashes due to insufficient stack space.
It is very strongly recommended to fix the code in question. The -fc-prototypes-external option can be used to generate prototypes which conform to gfortran's ABI, for inclusion in the source code.
Support for this option will likely be withdrawn in a future release of gfortran. Bestie, it's on borrowed time.
The negative form, -fno-tail-call-workaround or equivalent -ftail-call-workaround=0, can be used to disable this option.
Default is currently -ftail-call-workaround, this will change in future releases.
-fcheck-array-temporariesβ Deprecated alias for-fcheck=array-temps.-fmax-array-constructor=nβ This option can be used to increase the upper limit permitted in array constructors. The code below requires this option to expand the array at compile time.
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
Caution: This option can lead to long compile times and excessively large object files.
The default value for n is 65535.
-fmax-stack-var-size=nβ This option specifies the size in bytes of the largest array that will be put on the stack; if the size is exceeded static memory is used (except in procedures marked asRECURSIVE). Use the option-frecursiveto allow for recursive procedures which do not have aRECURSIVEattribute or for parallel programs. Use-fno-automaticto never use the stack.
This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables. Future versions of GNU Fortran may improve this behavior.
The default value for n is 65536.
-fstack-arraysβ Adding this option will make the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory. If your program uses very large local arrays it is possible that you will have to extend your runtime limits for stack memory on some operating systems. This flag is enabled by default at optimization level-Ofastunless-fmax-stack-var-sizeis specified.-fpack-derivedβ This option tells GNU Fortran to pack derived type members as closely as possible. Code compiled with this option is likely to be incompatible with code compiled without this option, and may execute slower. Incompatibility warning, bestie.-frepack-arraysβ In some circumstances GNU Fortran may pass assumed shape array sections via a descriptor describing a noncontiguous area of memory. This option adds code to the function prologue to repack the data into a contiguous block at runtime.
This should result in faster accesses to the array. However it can introduce significant overhead to the function call, especially when the passed data is noncontiguous.
-fshort-enumsβ This option is provided for interoperability with C code that was compiled with the-fshort-enumsoption. It will make GNU Fortran choose the smallestINTEGERkind a given enumerator set will fit in, and give all its enumerators this kind.-finline-arg-packingβ When passing an assumed-shape argument of a procedure as actual argument to an assumed-size or explicit size or as argument to a procedure that does not have an explicit interface, the argument may have to be packed, that is put into contiguous memory. An example is the call tofooin
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
When -finline-arg-packing is in effect, this packing will be performed by inline code. This allows for more optimization while increasing code size.
-finline-arg-packing is implied by any of the -O options except when optimizing for size via -Os. If the code contains a very large number of argument that have to be packed, code size and also compilation time may become excessive. If that is the case, it may be better to disable this option. Instances of packing can be found by using -Warray-temporaries.
-fexternal-blasβ This option will make gfortran generate calls to BLAS functions for some matrix operations likeMATMUL, instead of using our own algorithms, if the size of the matrices involved is larger than a given limit (see-fblas-matmul-limit). This may be profitable if an optimized vendor BLAS library is available. The BLAS library will have to be specified at link time.-fblas-matmul-limit=nβ Only significant when-fexternal-blasis in effect. Matrix multiplication of matrices with size larger than (or equal to)nwill be performed by calls to BLAS functions, while others will be handled by gfortran internal algorithms. If the matrices involved are not square, the size comparison is performed using 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 will be inlined. This may result in code size increase if the size of the matrix cannot be determined at compile time, as code for both cases is generated. Setting-finline-matmul-limit=0will disable inlining in all cases. Setting this option with a value ofnwill produce inline code for matrices with size up ton. If the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices.
The default value for n is 30. The -fblas-matmul-limit can be used to change this value.
-frecursiveβ okay so this one lets indirect recursion happen by forcing every single local array to be allocated on the stack. It's giving "just put it on the stack bestie" energy. But heads up: you cannot use this flag together with-fmax-stack-var-size=or-fno-automatic. They do not coexist, periodt.-finit-local-zero-finit-derived-finit-integer=n-finit-real=<zero|inf|-inf|nan|snan>-finit-logical=<true|false>-finit-character=nβ so the-finit-local-zerooption tells the compiler to initialize localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes. Slay, no more garbage values π . If you want finer control, there's a whole lil family of options:-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>(which also initializes the real and imaginary parts of localCOMPLEXvariables, cute),-finit-logical=<true|false>, and-finit-character=nβ wherenis an ASCII character value, iykyk.
With -finit-derived, components of derived type variables get initialized according to these flags too. Components whose type isn't covered by an explicit -finit-* flag get treated exactly as described above with -finit-local-zero. Consistent, we love that.
okay but these options do NOT initialize: - objects with thePOINTERattribute - allocatable arrays - variables that appear in anEQUIVALENCEstatement (these limitations may be removed in future releases β manifesting that fr π)
Also note: -finit-real=nan initializes REAL and COMPLEX variables with a quiet NaN. If you want a signalling NaN use -finit-real=snan β but careful bestie, compile-time optimizations may convert them into quiet NaN, and trapping needs to be enabled (e.g. via -ffpe-trap). It's giving "it might not do what you think".
The -finit-integer option will parse the value into an integer of type INTEGER(kind=C_LONG) on the host. Said value is then assigned to the integer variables in the Fortran code, which might result in wraparound if the value is too large for the kind. So like... mind your kinds β¨.
And finally: enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables. Yes, it's quiet. Maybe too quiet π.
-falign-commonsβ by default,gfortranenforces proper alignment of all variables in aCOMMONblock by padding them as needed. On certain platforms this is mandatory, on others it just increases performance. Iconic either way. But if aCOMMONblock is not declared with consistent data types everywhere, this padding can cause trouble, and-fno-align-commonscan be used to disable automatic alignment. Use the same form of this option for all files that share aCOMMONblock, fr fr. And to avoid potential alignment issues inCOMMONblocks, it's recommended to order objects from largest to smallest.-fno-protect-parensβ by default the parentheses in expressions are honored for all optimization levels, so the compiler doesn't do any re-association. Using-fno-protect-parenslets the compiler reorderREALandCOMPLEXexpressions to produce faster code π₯. Note that for the re-association optimization,-fno-signed-zerosand-fno-trapping-mathneed to be in effect. Parentheses protection is enabled by default, unless-Ofastis given.-frealloc-lhsβ an allocatable left-hand side of an intrinsic assignment is automatically (re)allocated if it's either unallocated or has a different shape. This option is enabled by default except when-std=f95is given. See also-Wrealloc-lhs. Bestie behavior, honestly π«Ά.-faggressive-function-eliminationβ functions with identical argument lists are eliminated within statements, regardless of whether these functions are markedPUREor not. For example, in
a = f(b,c) + f(b,c)
there will only be a single call to f. One call. Not two. Frugal π
. This option only works if -ffrontend-optimize is in effect.
-ffrontend-optimizeβ this option performs front-end optimization, based on manipulating parts of the Fortran parse tree. Enabled by default by any-Ooption except-O0and-Og. Optimizations enabled by this option include:- inlining calls to
MATMUL, - elimination of identical function calls within expressions,
- removing unnecessary calls to
TRIMin comparisons and assignments, - replacing
TRIM(a)witha(1:LEN_TRIM(a))and - short-circuiting of logical operators (
.AND.and.OR.).
- inlining calls to
It can be deselected by specifying -fno-frontend-optimize.
-ffrontend-loop-interchangeβ attempt to interchange loops in the Fortran front end where profitable. Enabled by default by any-Ooption. At the moment, this option only affectsFORALLandDO CONCURRENTstatements with several forall triplets. It's giving "rearranging the furniture for maximum efficiency" π¦.
πΈ ENVIRONMENT πΈ
The gfortran compiler currently does not make use of any environment variables to control its operation above and beyond those that affect the operation of gcc. So like, no secret env vars here bestie, it's a no-frills situation.
π BUGS π
For instructions on reporting bugs, see <file:///usr/share/doc/gcc-13/README.Bugs>. Go tell them everything, they wanna know π«Ά.
π 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. The whole friend group, honestly π
π AUTHOR π
See the Info entry for gfortran for contributors to GCC and GNU Fortran. Iconic legends, every single one.
β COPYRIGHT β
Copyright (c) 2004-2023 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being "Funding Free Software", the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the gfdl(7) man page.
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.
and that's a wrap on the whole page bestie πβ¨ this lil masterpiece is gcc-13, dated 2024-09-04, and it lives in the GFORTRAN(1) section of your manual. Go compile something iconic with it. periodt ππ
π¦
π¦ where this page comes from
- ubuntu noble: gfortran-13-mipsisa32r6-linux-gnu 13.3.0-6ubuntu2~24.04cross1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms