GFORTRAN(1)
π GFORTRAN π
okay bestie, gather round, because we're talking about the GNU Fortran compiler β gfortran. She's part of the GNU family, she speaks Fortran, and she's about to be your whole personality for the next eight parts. π
πΈ NAME πΈ
gfortran β the GNU Fortran compiler. that's it. short, sweet, iconic, no notes. π
π¦ SYNOPSIS π¦
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
real talk: this is just the snack-size version. only the most useful options are listed here β see below for the remainder, because there is so much remainder. π
π DESCRIPTION π
so here's the vibe. the gfortran command supports all the options supported by the gcc command. only the options that are specific to GNU Fortran are documented here, because the rest already live in the gcc manual. iykyk. β¨
all GCC and GNU Fortran options are accepted both by gfortran and by gcc (as well as by any other drivers built at the same time, such as g++) β because adding GNU Fortran to the GCC distribution enables acceptance of GNU Fortran options by all of the relevant drivers. they all share the same brain cell, essentially. π§
and in some cases, options have positive and negative forms β the negative form of -ffoo would be -fno-foo, obviously. this manual documents only one of these two forms, whichever one is not the default. so if you're looking for the other one, it's implied, babe. π«Ά
π OPTIONS π
here's a summary of all the options specific to GNU Fortran, grouped by type. explanations are in the following sections, so don't panic, we'll get there. π
π 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 -fopenmp-allocators -fopenmp-simd -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 -funsigned
πΈ 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 -Wno-deprecated-openmp -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 -Wundefined-vars -Wunused-intent-out -Wunused-read -fmax-errors=n -fsyntax-only -pedantic -pedantic-errors
π Debugging Options
-fbacktrace -fdebug-aux-vars -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|shared|lib> -fexternal-blas -fexternal-blas64 -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-intrinsics[=<minloc,maxloc>] -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
π οΈ Developer Options
-fdump-fortran-global -fdump-fortran-optimized -fdump-fortran-original -fdump-parse-tree -save-temps
π Options controlling Fortran dialect π
the following options control the details of the Fortran dialect accepted by the compiler. this is where you decide which flavor of Fortran she's going to speak to you in. π
-ffree-form,-ffixed-formβ specify 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 is determined by the file extension. so yes, the filename is doing the talking, bestie. π-fall-intrinsicsβ this option causes all intrinsic procedures (including the GNU-specific extensions) to be accepted. this can be useful with-std=to force standard compliance but still get access to the full range of intrinsics available withgfortran. as a consequence,-Wintrinsics-stdis ignored and no user-defined procedure with the same name as any intrinsic is called, except when it is explicitly declaredEXTERNAL. so it's a package deal, lowkey. β¨-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 nonconforming, and is usually flagged with an error. this option degrades the error to a warning that 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.
using this option is strongly discouraged. it is possible to provide standard-conforming code that allows different types of arguments by using an explicit interface and TYPE(*). so likeβ¦ you can, but should you? no babe. π
-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. living dangerously, we love that for you. π-fd-lines-as-code,-fd-lines-as-commentsβ enable special treatment for lines beginning withdorDin fixed form sources. if the-fd-lines-as-codeoption is given, they are treated as if the first column contained a blank. if the-fd-lines-as-commentsoption is given, they are treated as comment lines. same letters, very different energy. π¦-fdecβ DEC compatibility mode. enables extensions and other features that mimic the default behavior of older compilers (such as DEC). these features are nonstandard 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 andDATAstatements for non-character variables. cute, a little chaotic, very DEC. π-fdec-structureβ enable DECSTRUCTUREandRECORDas well asUNION,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. periodt. π-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 Intrinsic Procedures.-fdec-mathβ obsolete flag. the purpose of this option was to enable legacy math intrinsics such asCOTANand degree-valued trigonometric functions (e.g.TAND,ATAND, etc...) for compatibility with older code. this option is no longer operable. the trigonometric functions are now either part of Fortran 2023 or GNU extensions. she's retired, she's living her best life, let her rest. π-fdec-staticβ enable DEC-styleSTATICandAUTOMATICattributes to explicitly specify the storage of variables and other objects.-fdec-includeβ enable parsing ofINCLUDEas a statement in addition to parsing it asINCLUDEline. when parsed asINCLUDEstatement,INCLUDEdoes not have to be on a single line and can use line continuations. so much more room to breathe. π-fdec-format-defaultsβ enable format specifiersF,GandIto be used without width specifiers; default widths are 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. just a lil dangling comma vibes. π-fdollar-okβ allow$as a valid non-first character in a symbol name. symbols that start with$are rejected since it is unclear which rules to apply to implicit typing as different vendors implement different rules. using$inIMPLICITstatements is also rejected. rules are rules, babe. π-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\0to the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. additionally,\xnn,\unnnnand\Unnnnnnnn(where eachnis 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. so like, don't get cute with random backslashes. π-fmodule-privateβ set the default accessibility of module entities toPRIVATE. use-associated entities are not accessible unless they are explicitly declared asPUBLIC. boundaries, bestie! we're setting boundaries! π«Ά-ffixed-line-length-nβ set 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. math is math. π
-fno-pad-sourceβ okay so by default, fixed-form lines act like there are spaces after the end of short lines, as if they got padded out to that length. This lil option says nope, don't do that π . It also doesn't happen if-ffixed-line-length-0or-ffixed-line-length-noneis used, or if-fno-pad-sourceis on. And with any of those options, continued character constants never get implicit spaces appended to them to fill out the line. periodt.-ffree-line-length-nβ sets the column after which characters are ignored in typical free-form lines in the source file. The default value is 132.ncan benone, which means the entire line is meaningful (no ignoring, bestie). And just so you know,-ffree-line-length-0means the exact same thing as-ffree-line-length-none. π-fmax-identifier-length=nβ the maximum allowed identifier length, fr. Typical values are31(Fortran 95) and63(Fortran 2003 and later).-fimplicit-noneβ says no implicit typing allowed, unless explicitIMPLICITstatements override it. It's literally the equivalent of addingimplicit noneat the start of every procedure. chef's kiss β¨-fcray-pointerβ enables the Cray pointer extension, which hands you C-like pointer functionality. π«Ά-fopenaccβ enables handling of OpenACC directives:!$accin free-form Fortran, and!$acc,c$accand*$accin fixed-form Fortran. When-fopenaccis specified, the compiler generates accelerated code according to the OpenACC Application Programming Interface v2.6 (https://www.openacc.org). Heads up bestie: this option implies-pthread, so it's only supported on targets that support-pthread. And-fopenaccimplies-frecursive. π-fopenmpβ enables handling of OpenMP directives!$ompin Fortran. It also switches on the conditional compilation sentinel!$in Fortran. In fixed source form Fortran, those sentinels can also start withcor*. When-fopenmpis specified, the compiler generates parallel code according to the OpenMP Application Program Interface v4.5 (https://www.openmp.org). This option implies-pthread, so again, only supported on targets that have support for-pthread. And-fopenmpimplies-fopenmp-simdand-frecursive. π₯-fopenmp-allocatorsβ enables handling of allocation, reallocation and deallocation of Fortran allocatable and pointer variables that get allocated using the!$omp allocatorsand!$omp allocateconstructs. Big deal incoming π: files containing either directive have to be compiled with this option in addition to-fopenmp. Also, all files that might deallocate or reallocate a variable that has been allocated with an OpenMP allocator have to be compiled with this option. That includes intrinsic assignment to allocatable variables when reallocation may occur, and deallocation due to either of the following: end of scope, explicit deallocation,intent(out), deallocation of allocatable components, etc. Files that don't change the allocation status β or only do for components of a derived type that have not been allocated using those two directives β don't need this option. Nor do files that handle such variables after they've been deallocated or allocated by the normal Fortran allocator. iykyk.-fopenmp-simdβ enables handling of OpenMP'ssimd,declare simd,declare reduction,assume,ordered,scanandloopdirective, plus combined or composite directives withsimdas constituent with!$ompin Fortran. It additionally enables the conditional compilation sentinel!$in Fortran. In fixed source form Fortran, the sentinels can also start withcor*. Other OpenMP directives are just ignored. And unless-fopenmpis additionally specified, theloopregion binds to the current task region, independent of the specifiedbindclause. π
-fno-range-checkβ disables range checking on results of simplification of constant expressions during compilation. For example, GNU Fortran throws an error at compile time when simplifyinga = 1. / 0. With this option, no error is given andagets assigned the value+Infinity. If an expression evaluates to a value outside of the relevant range of[-HUGE():HUGE()], then the expression is replaced by-Infor+Infas appropriate. Similarly,DATA i/Z'FFFFFFFF'/results in an integer overflow on most systems, but with-fno-range-checkthe value "wraps around" andiis initialized to-1instead. π-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 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 option 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. And 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 option 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 with-fdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. And 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 option 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 with-fdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. And 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. Does nothing if that's already the default. 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, then an error is issued. β οΈ Use this one with care, bestie, 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. 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β promotes allREAL(KIND=M)entities toREAL(KIND=N)entities. IfREAL(KIND=N)is unavailable, then an error is 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 also gets 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-originalor-fdump-tree-original, is suggested. NOTE: These options are incompatible with user defined derived type I/O (DTIO). π-std=stdβ specifies the standard to which the program is expected to conform, which may be one off95,f2003,f2008,f2018,f2023,gnu, orlegacy. The default value for std isgnu, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran β although warnings are 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 nonstandard programs. Thef95,f2003,f2008,f2018, andf2023values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008, Fortran 2018 and Fortran 2023 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=f2008tsacts as an alias for-std=f2018. It's only present for backwards compatibility with earlier gfortran versions and should not be used any more, fr fr. And-std=f202yacts as an alias for-std=f2023and enables proposed features for testing Fortran 202y β as the Fortran 202y standard develops, implementation might change or the experimental new features might be removed. π¦-ftest-forall-tempβ enhances test coverage by forcing most forall assignments to use temporary.-funsignedβ allows the experimental unsigned extension. π§ͺ
β¨ Enable and customize preprocessing β¨
okay bestie, let's talk preprocessing π
Many Fortran compilers including GNU Fortran let you pass the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) so you can do conditional compilation. In GNU Fortran's case, it's 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 β and to disable preprocessing on files where the preprocessor is run automatically, use -nocpp.
When compiling a preprocessed file, use -fpreprocessed. This skips the C preprocessor.
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 predefined 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.
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 filefoo.f90, the command
touch foo.f90; gfortran -cpp -E -dM foo.f90
shows all the predefined macros.
-dDβ Like-dMexcept 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 emit only the macro names, not their expansions.-dUβ LikedDexcept that 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β Output#includedirectives in addition to the result of preprocessing.-fworking-directoryβ Enable 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 uses 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 this can be inhibited with the negated form-fno-working-directory. If the-Pflag is present in the command line, this option has no effect, since no#linedirectives are emitted whatsoever.-idirafter dirβ Searchdirfor include files, but do it after all directories specified with-Iand the standard system directories have been exhausted.diris treated as a system include directory. Ifdirbegins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-imultilib dirβ Usediras a subdirectory of the directory containing target-specific C++ headers.-iprefix prefixβ Specifyprefixas the prefix for subsequent-iwithprefixoptions. If the prefix represents a directory, you should include the final/.-isysroot dirβ This option is like the--sysrootoption, but applies only to header files. See the--sysrootoption for more information.-iquote dirβ Searchdironly for header files requested with#include "file"; they are not searched for#include <file>, before all directories specified by-Iand before the standard system directories. Ifdirbegins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-isystem dirβ Searchdirfor header files, after all directories specified by-Ibut before the standard system directories. Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. Ifdirbegins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-nostdincβ Do not search the standard system directories for header files. Only the directories you have specified with-Ioptions (and the directory of the current file, if appropriate) are 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 predicatepredicateand answeranswer. This form is preferred to the older form-A predicate(answer), which is still supported, because it does not use shell special characters.-A-predicate=answerβ Cancel an assertion with the predicatepredicateand answeranswer.-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β Predefinenameas a macro, with definition1.-Dname=definitionβ The contents ofdefinitionare tokenized and processed as if they appeared during translation phase three in a#definedirective. In particular, the definition is truncated by embedded newline characters.
If you are 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 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#includestack 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 is sent to a program that might be confused by the linemarkers.-Unameβ Cancel any previous definition ofname, 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 continues to process the program in an attempt to report further errors to aid in debugging, but does not produce any compiled output.
Warnings are diagnostic messages that report constructions that are not inherently erroneous but that 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 ton, at which point GNU Fortran bails out rather than attempting to continue processing the source code. Ifnis0, there is no limit on the number of error messages produced.-fsyntax-onlyβ okay so this one just checks your code for syntax errors, it does not actually compile, bestie. No object files, no nothing. It will still generate module files for every module in your code though β that's the only output it makes. π-Wpedantic,-pedanticβ yells at you for using extensions to Fortran.-pedanticalso hits C-language constructs when they show up in GNU Fortran source files, like using\einside a character constant within a directive such as"#include".
Valid Fortran programs should compile fine whether or not you turn this on. But lowkey β without this option, certain GNU extensions and some traditional Fortran features are supported too. With it on, a whole bunch of them get rejected. π
Some people try to use -pedantic to check their programs for conformance. They find out real fast that it does not do quite what they want β it catches some nonstandard practices, but not all of them. That said, improvements to GNU Fortran in this area are welcome. π
You should use this alongside -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023.
-pedantic-errorsβ same vibe as-pedantic, except you get errors instead of warnings. No notes. β¨-Wallβ turns on the warning options we consider the everyday ones: usage we recommend avoiding and that we think is easy to avoid. Right now that's-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunused,-Wundefined-do-loopand-Wundefined-vars. the whole squad β¨
-Waliasingβ warns about possible aliasing of dummy arguments. Specifically: it warns if the same actual argument gets associated with a dummy argument withINTENT(IN)and a dummy argument withINTENT(OUT)in a call with an explicit interface. Bestie that is a crime scene.
This here example triggers 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. You get this warning with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-std=f2023. Note: if there's no ampersand in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that started the continuation. iykyk π-Warray-temporariesβ warns about array temporaries the compiler generates. Honestly the info this warning gives you is sometimes useful for optimization, so you can dodge those temporaries. optimization girlies rise π§-Wc-binding-typeβ warns if a variable might not be C interoperable. More specifically: it warns if the variable was declared with an intrinsic type with default kind instead of a kind parameter defined for C interoperability in the intrinsicISO_C_Bindingmodule. This option is implied by-Wall. π¦-Wcharacter-truncationβ warns when a character assignment truncates the assigned string. rip that string π-Wline-truncationβ warns when a source code line gets truncated. This one 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 would likely change the value of the expression after conversion. Implied by-Wall. π«Ά-Wconversion-extraβ warns about implicit conversions between different types and kinds. Heads up: this option does not imply-Wconversion.-Wdeprecated-openmpβ warns when deprecated OpenMP code is being used. old news, babes-Wexternal-argument-mismatchβ warns about argument mismatches for dummy external procedures. Implied by-fc-prototypes-external, because generating a valid C23 interface simply isn't possible in that case. Also implied by-Wall.-Wextraβ turns on some warning options for language features that could be problematic. Right now that's-Wcompare-reals,-Wunused-parameter,-Wdo-subscript,-Wunused-intent-outand-Wunused-read.-Wfrontend-loop-interchangeβ warns when-ffrontend-loop-interchangeis doing loop interchanges. π₯-Wimplicit-interfaceβ warns if a procedure gets 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. half a vibe check, but ok-Wimplicit-procedureβ warns if a procedure gets called that has neither an explicit interface nor has been declared asEXTERNAL.-Winteger-divisionβ warns if a constant integer division truncates its result. Example:3/5evaluates to0. π-Wintrinsics-stdβ warns if gfortran finds a procedure named like an intrinsic that isn't available in the standard you've currently selected (via-std) and treats it as anEXTERNALprocedure because of that. You can use-fall-intrinsicsto never trigger this behavior and always link to the intrinsic no matter which standard is selected. no cap-Wno-overwrite-recursiveβ don't warn when-fno-automaticis used together with-frecursive. Recursion is 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. Useful for build environments that use-Werror. π€-Wreal-q-constantβ produces a warning if a real-literal-constant contains aqexponent-letter. just... why tho-Wsurprisingβ produces a warning when "suspicious" code constructs show up. Technically they're legal, but they usually mean somebody made a mistake. π
Right now it produces a warning in these cases:
- An
INTEGER-typedSELECT CASEconstruct has aCASEthat can never be matched, because its lower value is greater than its upper value. - A
LOGICAL-typedSELECT CASEconstruct 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.) - With
-fopenacc, when using named constants with clauses that take a variable, since doing so has no effect.
-Wtabsβ 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 between1and9is supported.-Wtabsmakes a warning pop up whenever a tab is encountered. Note:-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018,-std=f2023and-Wall. β¨-Wundefined-do-loopβ warns if aDOloop with step either1or-1yields an underflow or an overflow while iterating an induction variable of the loop. This option is implied by-Wall. π-Wundefined-varsβ warns if variables are found being used that cannot be defined (meaning nothing ever assigns a value to them). This also covers using allocatable variables that aren't allocated.-Wunderflowβ produces a warning when numerical constant expressions that yield an underflow are encountered during compilation. enabled by default, she's always watching π-Wintrinsic-shadowβ warns if a user-defined procedure or module procedure has the same name as an intrinsic. In that case you might need an explicit interface, or anEXTERNALorINTRINSICdeclaration, to get calls later resolved to the intrinsic/procedure you actually wanted. This option is implied by-Wall. π-Wuse-without-onlyβ warns if aUSEstatement has noONLYqualifier, which means it implicitly imports every public entity of the used module. sneaky import behavior fr fr-Wunused-dummy-argumentβ warns about unused dummy arguments. This option is implied by-Wall.-Wunused-parameterβ okay this is not like gcc's meaning of-Wunused-parameter. gfortran's implementation of this option does not warn about unused dummy arguments (that's-Wunused-dummy-argument), it warns about unusedPARAMETERvalues.-Wunused-parameteris implied by-Wextraif-Wunusedor-Wallis also used. π«-Wunused-intent-outβ warns about variables passed toINTENT(OUT)arguments whose values then go unused. This option is implied by-Wextra. Here's a code example where the warning gets emitted:
module y
implicit none
contains
subroutine bar
real :: a
call foo(a) ! Warning will be emitted here
end subroutine bar
subroutine foo(x)
real, intent(out) :: x
x = 0.4
end subroutine foo
end module y
-Wunused-readβ warns about variables inREADstatements whose values are never used. Implied by-Wextra. Example where this warning gets emitted:
program main
real :: x
read (*,*) x
end program main
-Walign-commonsβ by default, gfortran warns any time variables get padded for proper alignment inside aCOMMONblock. You can turn that warning off with-Wno-align-commons. See also-falign-commons. padding drama π-Wfunction-eliminationβ warns if any calls to impure functions get eliminated by the optimizations that-ffrontend-optimizeenables. This option is implied by-Wextra. π-Wrealloc-lhsβ bestie, this one yells at you when the compiler might sneak in code to allocate or reallocate an allocatable array variable of intrinsic type during intrinsic assignments. In hot loops, that Fortran 2003 reallocation feature can lowkey tank your performance π. If your array is already allocated with the right shape, use a whole-array array-spec (like(:,:,:)) on the left-hand side variable to dodge the reallocation check. Heads up though: sometimes the warning shows up even when the compiler optimizes the reallocation checks away β for instance, when the right-hand side has the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allβ same vibe, but extra π : warns whenever the compiler inserts code to allocate or reallocate an allocatable variable, and yes that includes scalars and derived types too.-Wcompare-realsβ warns when you're comparing real or complex types for equality or inequality (iykyk, that's a trap π). This option is implied by-Wextra.-Wtarget-lifetimeβ warns if the pointer in a pointer assignment might live longer than its target π. This option is implied by-Wall.-Wzerotripβ warns if aDOloop is known to execute zero times at compile time. This option is implied by-Wall.-Wdo-subscriptβ warns when an array subscript inside aDOloop could cause an out-of-bounds access, even if the compiler can't prove the statement actually gets executed. Like in cases such as:
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. No more "it's just a warning" energy π.
Some of these have no effect when compiling programs written in Fortran. Periodt.
π Options for debugging your program π
GNU Fortran has various special options that get used for debugging your program. Let's go β¨
-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 uppercase letters followed by an underscore. This one is useful for debugging the compiler's code generation alongside-fdump-tree-original, and for enabling debugging of the executable program by using-gor-ggdb3.- *
-ffpe-trap=list* β specify 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 gets sent and the program gets aborted, producing a core file that's useful for debugging. list is a (possibly empty) comma-separated list of eithernone(to clear the set of exceptions to be trapped), or of these exceptions here:invalidβ invalid floating point operation, such asSQRT(-1.0)zeroβ division by zerooverflowβ overflow in a floating point operationunderflowβ underflow in a floating point operationinexactβ loss of precision during operationdenormalβ 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) often indicate serious errors, and unless the program has provisions for dealing with these exceptions, enabling traps for these three is probably a good idea π.
If the option is used more than once in the command line, the lists are joined: "ffpe-trap="list1 "ffpe-trap="list2 is equivalent to "ffpe-trap="list1,list2.
Note that once enabled, an exception cannot be disabled (no negative form), except by clearing all traps by specifying none. π
Many, if not most, floating point operations incur loss of precision due to rounding, and hence the "ffpe-trap=inexact" is likely to be uninteresting in practice π₯±.
By default no exception traps are enabled.
- *
-ffpe-summary=list* β specify a list of floating-point exceptions whose flag status gets printed toERROR_UNITwhen invokingSTOPandERROR STOP. list can be eithernone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (Peep-ffpe-trapfor a description of the exceptions β¨)
If the option is used more than once in the command line, only the last one is used.
By default, a summary for all exceptions but inexact is shown.
-fno-backtraceβ when a serious runtime error is encountered or a deadly signal is emitted (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 output a backtrace of the error.-fno-backtracedisables the backtrace generation. Heads up: this option only has influence for compilation of 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.
It also affects the search paths used by cpp when cpp is used to preprocess Fortran source β¨
-Idirβ these affect interpretation of theINCLUDEdirective (as well as of the#includedirective of the cpp preprocessor).
Also note that the general behavior of -I and INCLUDE is pretty much the same as of -I with #include in the cpp preprocessor, with regard to looking for header.gcc files and other such things.
This path is also used to search for .mod files when previously compiled modules are required by a USE statement π
-Jdirβ this option specifies where to put.modfiles for compiled modules. It's also added to the list of directories to be searched by aUSEstatement.
The default is the current directory π
- *
-fintrinsic-modules-pathdir* β this option specifies the location of pre-compiled intrinsic modules, if they're not in the default location expected by the compiler.
π Influencing the linking step π«Ά
These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler isn't doing a link step, so no cap.
-static-libgfortranβ on systems that provide libgfortran as both a shared and a static library, this option forces the use of the static version. If no shared version of libgfortran was built when the compiler was configured, this option has no effect.-static-libquadmathβ on systems that provide libquadmath as both a shared and a static library, this option forces the use of the static version. If no shared version of libquadmath was built when the compiler was configured, this option has no effect.
Please note that 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 β οΈ
π Influencing runtime behavior π
These options affect the runtime behavior of programs compiled with GNU Fortran β¨
- *
-fconvert=conversion* β specify the representation of data for unformatted files π. Valid values for conversion on most systems are:native, the default;swap, swap between big- and little-endian;big-endian, use big-endian representation for unformatted files;little-endian, use little-endian representation for unformatted files.
On POWER systems that support -mabi=ieeelongdouble, there are additional options, which can be combined with others with 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 has an effect only when used in the main program. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable override the default specified by -fconvert π
- *
-frecord-marker=length* β specify 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* β specify 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 π§ͺ. -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 theSIGNintrinsic.-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 theSIGNintrinsic, for compatibility with Fortran 77. The default is-fsign-zero.
π οΈ GNU Fortran Developer Options π§
GNU Fortran has various special options that get used for debugging the GNU Fortran compiler itself. Very main character energy of it π
-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 that 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 that have only recently been added π-fdump-fortran-originalβ outputs the internal parse tree after translating the source program into internal representation. This option is 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 that have only recently been added π-fdump-parse-treeβ Dumps out the internal parse tree once the source program has been translated into internal representation. Honestly it's mostly for debugging the GNU Fortran compiler itself π οΈ. Heads up: the output this generates might change between releases, and it may also throw internal compiler errors for features that were only recently added. This option is deprecated β use-fdump-fortran-originalinstead, bestie.-save-tempsβ Keeps the usual "temporary" intermediate files around forever instead of ghosting them; it names them as auxiliary output files, as described under GCC-dumpbaseand-dumpdir.
gfortran -save-temps -c foo.F90
that ^ preprocesses input file foo.F90 to foo.fii, compiles to an intermediate foo.s, and then assembles to the (implied) output file foo.o, whereas:
gfortran -save-temps -S foo.F
saves the preprocessor output in foo.fi, and then compiles to the (implied) output file foo.s. π
β¨ Options for code generation conventions β¨
These machine-independent options control the interface conventions used in code generation. Very "this is how we talk to each other" energy.
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 that is not the default. You can figure out the other form by either removing no- or adding it. Slay, you got this. π
-fno-automaticβ Treats each program unit (except those marked asRECURSIVE) as if theSAVEstatement were specified for every local variable and array referenced in it. Does not affect common blocks. (Some Fortran compilers dish out 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 to store the return value. 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 as, callingCOMPLEXor defaultREALfunctions between program parts that were compiled with different calling conventions will break at execution time. π
Caution: This breaks code that passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, as 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. Note this does not apply to names declared with C binding, or within a module.
Caution: The default behavior of GNU Fortran is incompatible withf2candg77, 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 are experimenting with issues such as integration of 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 Fortran statement like
I = J() + MAX_COUNT (MY_VAR, LVAR)
is implemented as something akin to the C code:
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 conflicts 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. Not the vibe you want fr fr.
Also note that declaring symbols as bind(C) is a more robust way to interface with code written in other languages or compiled with different Fortran compilers than the command-line options documented in this section. π
-fsecond-underscoreβ By default, GNU Fortran appends an underscore to external names. If this option is used, GNU Fortran appends two underscores to names with underscores and one underscore to names with no underscores.
For example, 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.
This option has no effect if -fno-underscoring is in effect. It is implied by the -ff2c option.
-fcoarray=<keyword>β Coarray time π, here are the keywords:noneβ Disable coarray support; using coarray declarations and image-control statements produces a compile-time error. (Default)singleβ Single-image mode, i.e.num_images()is always one.sharedβ Use shared-memory multithreading parallelization.libβ Library-based coarray parallelization; a suitable GNU Fortran coarray library such as <http://opencoarrays.org> needs to be linked. Alternatively, GCC'slibcaf_singlelibrary can be linked, albeit it only supports a single image. π
-fcheck=<keyword>β Enables 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.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=bounds is set for the compilation of the main program.
Note: In the future this may also include other forms of checking, e.g., checking substring references.
doβ 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 theALLOCATEstatement, which are 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 that 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
compiles the file with all checks enabled as specified above except warnings for generated array temporaries. β¨
-fbounds-checkβ Deprecated alias for-fcheck=bounds. It's giving legacy, ngl.-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 that 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. π (not me mourning a deprecated flag, anyway)
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. β οΈ heads up bestie, the default is movable.
-fcheck-array-temporariesβ deprecated alias for-fcheck=array-temps. That's it, that's the whole vibe. π-fmax-array-constructor=nβ this one lets you raise the upper limit permitted in array constructors π. Like, the code below literally 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. π your build will be in its flop era, fr fr.
The default value for n is 65535.
-fmax-stack-var-size=nβ sets the size in bytes of the largest array that is put on the stack π. If the size is exceeded, static memory is used instead (except in procedures marked asRECURSIVE). Use the option-frecursiveto allow for recursive procedures that do not have aRECURSIVEattribute, or for parallel programs π. Use-fno-automaticto never use the stack at all.
Real talk: 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 makes the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory π₯. If your program uses very large local arrays, it's possible you 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β tells GNU Fortran to pack derived type members as closely as possible π§³. Heads up though: code compiled with this option is likely to be incompatible with code compiled without it, and may execute slower. π trade-offs are real.-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. So like, it's giving speed but it's also giving cost, iykyk.
-fshort-enumsβ provided for interoperability with C code that was compiled with the-fshort-enumsoption π€. It makes GNU Fortran choose the smallestINTEGERkind a given enumerator set fits 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 is 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 makes 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 has to be specified at link time. This option specifies a BLAS library with integer arguments of default kind (32 bits). It cannot be used together with-fexternal-blas64. π«-fexternal-blas64β makes 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 has to be specified at link time. This option specifies a BLAS library with integer arguments ofKIND=8(64 bits). It cannot be used together with-fexternal-blas, and requires a 64-bit system π₯οΈ. This option also requires-ffrontend-optimize.-fblas-matmul-limit=nβ only significant when-fexternal-blasor-fexternal-blas64are in effect π. Matrix multiplication of matrices with size larger than or equal to n is performed by calls to BLAS functions, while others are 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-intrinsics-finline-intrinsics=intr1,intr2,...β prefer generating inline code over calls to libgfortran functions to implement intrinsics π .
Usage of intrinsics can be implemented either by generating a call to the libgfortran library function or by directly generating inline code. For most intrinsics, only a single variant is available, and there is no choice of implementation. However, some intrinsics can use a library function or inline code, where inline code typically offers opportunities for additional optimization over a library function π₯. With -finline-intrinsics=... or -fno-inline-intrinsics=..., the choice applies only to the intrinsics present in the comma-separated list provided as argument.
For each intrinsic, if no choice of implementation was made through either of the flag variants, a default behavior is chosen depending on optimization: library calls are generated when not optimizing or when optimizing for size; otherwise inline code is preferred.
The set of intrinsics allowed as argument to -finline-intrinsics= is currently limited to MAXLOC and MINLOC π. The effect of the flag is moreover limited to calls of those intrinsics without DIM argument and with ARRAY of a non-CHARACTER type. The case of rank-1 argument and DIM argument present, i.e. MAXLOC(A(:),DIM=1) or MINLOC(A(:),DIM=1) is inlined unconditionally for numeric rank-1 array argument A β¨.
-finline-matmul-limit=nβ when front-end optimization is active, some calls to theMATMULintrinsic function are 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=0disables inlining in all cases. Setting this option with a value of n produces inline code for matrices with size up to n. 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β allow indirect recursion by forcing all local arrays to be allocated on the stack π₯. This flag cannot be used together with-fmax-stack-var-size=or-fno-automatic. Pick a lane bestie π«.-finit-local-zero-finit-derived-finit-integer=n-finit-real=<zero|inf|-inf|nan|snan>-finit-logical=<true|false>-finit-character=nβ okay so the-finit-local-zerooption instructs the compiler to initialize localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes π«Ά. Finer-grained initialization options are provided by the-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>(which also initializes the real and imaginary parts of localCOMPLEXvariables),-finit-logical=<true|false>, and-finit-character=n(where n is an ASCII character value) options π.
With -finit-derived, components of derived type variables are initialized according to these flags. Components whose type is not covered by an explicit -finit-* flag are 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 the -finit-real=nan option initializes REAL and COMPLEX variables with a quiet NaN π΄. For a signalling NaN use -finit-real=snan; note, however, that compile-time optimizations may convert them into quiet NaN and that 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. 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 π.
Finally, note that enabling any of the -finit-* options silences warnings that would have been emitted by -Wuninitialized for the affected local variables π.
-falign-commonsβ okay so by defaultgfortranis out here making sure every variable in aCOMMONblock is properly aligned, padding them as needed. On some platforms this is literally mandatory, on others it just makes stuff faster. But bestie, if aCOMMONblock isn't declared with consistent data types everywhere, that padding can cause trouble π, and you can use-fno-align-commonsto turn off automatic alignment. Pro tip: use the same form of this option for every file that shares aCOMMONblock. And to dodge alignment drama inCOMMONblocks, order objects from largest to smallest. π-fno-protect-parensβ so like, by default the parentheses in expressions are honored at all optimization levels, meaning the compiler won't do any reassociation. But if you use-fno-protect-parens, the compiler can reorderREALandCOMPLEXexpressions to make faster code π₯. Just note: for that reassociation optimization,-fno-signed-zerosand-fno-trapping-mathneed to be in effect. Parentheses protection is enabled by default, unless you pass-Ofast. π-frealloc-lhsβ an allocatable left-hand side of an intrinsic assignment gets automatically (re)allocated if it's either unallocated or has a different shape. This is enabled by default except when-std=f95is given. Also peep-Wrealloc-lhs. β¨-faggressive-function-eliminationβ functions with identical argument lists get eliminated within statements, no matter if they're markedPUREor not. For example, in
a = f(b,c) + f(b,c)
there's only a single call to f. This option only works if -ffrontend-optimize is in effect. π
-ffrontend-optimizeβ this does front-end optimization by manipulating parts of the Fortran parse tree. It's enabled by default by any-Ooption except-O0and-Og. Optimizations it turns on include:- inlining calls to
MATMUL, - elimination of identical function calls within expressions,
- removing unnecessary calls to
TRIMin comparisons and assignments, - replacing
TRIM(a)witha(1:LEN_TRIM(a)), and - short-circuiting of logical operators (
.AND.and.OR.).
- inlining calls to
You can deselect it by specifying -fno-frontend-optimize. π
-ffrontend-loop-interchangeβ attempt to interchange loops in the Fortran front end where it's profitable. Enabled by default by any-Ooption. At the moment, this only affectsFORALLandDO CONCURRENTstatements with several forall triplets. π¦
π 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 extra env vars for you here, bestie. β¨
π BUGS π
For instructions on reporting bugs, see <https://gcc.gnu.org/bugs/>. π
π SEE ALSO π
You should also peep: 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 βοΈ
See the Info entry for gfortran for contributors to GCC and GNU Fortran. π«Ά
π COPYRIGHT π
Copyright (c) 2004-2026 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! This page is from gcc-17, dated 2026-09-20, and it's the GFORTRAN(1) man page. Stay iconic, bestie! π
πβ¨
π¦ where this page comes from
- ubuntu stonking: gcc-snapshot 1:20260920-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms