GFORTRAN(1)
๐ GFORTRAN(1) ๐
okay bestie, welcome to GFORTRAN(1) โ that's the GNU manual page for the one and only gfortran compiler, and she is long, so hydrate before we start ๐งโจ
โจ NAME โจ
gfortran โ the GNU Fortran compiler ๐
๐ธ SYNOPSIS ๐ธ
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
and before you ask โ only the most useful options are up there, like the highlight reel. The rest are further down this page, and yes we're going through all of them ๐
๐ฆ DESCRIPTION ๐ฆ
so the gfortran command supports all the options that the gcc command supports. But this manual? It only documents the options that are specific to GNU Fortran. That's it, that's the scope ๐
here's the cute part: all GCC options and all GNU Fortran options are accepted by both gfortran and gcc โ and by any other drivers built at the same time too, like g++. Why? Because the moment GNU Fortran got added to the GCC distribution, all the relevant drivers started accepting GNU Fortran options. everybody's invited to the party ๐ซถ
also, some options come in a positive form and a negative form โ the negative form of -ffoo would be -fno-foo. This manual only documents one of the two forms, and it picks whichever one is not the default. iykyk ๐
๐ OPTIONS ๐
here's the summary of every option that's specific to GNU Fortran, grouped by type ๐ explanations live in the sections that follow, bestie.
๐ 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
๐ 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 -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|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
๐ Developer Options
-fdump-fortran-global -fdump-fortran-optimized
-fdump-fortran-original -fdump-parse-tree -save-temps
๐ธ Options controlling Fortran dialect ๐ธ
these ones control the vibe of the Fortran dialect the compiler will accept, down to the details:
-ffree-form,-ffixed-formโ these set the layout the source file uses. Free form layout showed up in Fortran 90. Fixed form is what the older Fortran programs traditionally used. If you don't specify either one, the source form gets decided by the file extension. mystery solved ๐-fall-intrinsicsโ this one makes all intrinsic procedures get accepted, including the GNU-specific extensions. Super useful together with-std=when you want to force standard-compliance but still get access to the full range of intrinsicsgfortranhas to offer. Side effect tho:-Wintrinsics-stdgets ignored, and no user-defined procedure that shares a name with any intrinsic will be called โ unless it's explicitly declaredEXTERNAL. periodt.-fallow-argument-mismatchโ some code out there calls external procedures with mismatches between the calls and the procedure definition, or mismatches between different calls. That code is non-conforming, and usually it gets flagged with an error. This option downgrades the error to a warning, and that warning can only be silenced by disabling all warnings via-w. Only a single occurrence per argument gets flagged by this warning. Also,-fallow-argument-mismatchis implied by-std=legacy.
bestie, using this option is strongly discouraged. You can write standard-conforming code that allows different types of arguments โ do that instead, with an explicit interface and TYPE(*). ๐จ
-fallow-invalid-bozโ a BOZ literal constant can only show up in a limited number of contexts in standard conforming Fortran. This option downgrades an error condition to a warning and lets a BOZ literal constant appear where the Fortran standard would otherwise forbid it. living dangerously, love that for you ๐-fd-lines-as-code,-fd-lines-as-commentsโ these turn on special treatment for lines that begin withdorDin fixed form sources. Give-fd-lines-as-codeand those lines are treated as if the first column contained a blank. Give-fd-lines-as-commentsand they're treated as comment lines. pick your fighter ๐-fdecโ DEC compatibility mode, bb. Enables extensions and other features that mimic the default behavior of older compilers (like DEC). These features are non-standard and should be avoided at all costs. For all the details on how GNU Fortran implements these extensions, see the full documentation.
other flags this switch turns on: -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
and if -fd-lines-as-code/-fd-lines-as-comments are unset, then -fdec also sets -fd-lines-as-comments.
-fdec-char-conversionsโ enables the use of character literals in assignments andDATAstatements for non-character variables. yes, really.-fdec-structureโ enables DECSTRUCTUREandRECORD, plusUNION,MAP, and dot (.) as a member separator (on top of%). This exists for compatibility only โ use Fortran 90 derived types instead wherever you can. it's giving legacy ๐ซถ-fdec-intrinsic-intsโ enables the B/I/J/K kind variants of existing integer functions (like BIAND, IIAND, JIAND, etc...). For the complete list of intrinsics, check the full documentation.-fdec-mathโ obsolete flag, bestie. The whole point of it was to enable legacy math intrinsics such as COTAN and degree-valued trigonometric functions (like TAND, ATAND, etc...) for compatibility with older code. This option is no longer operable. Those trigonometric functions are now either part of Fortran 2023 or GNU extensions. she's retired ๐-fdec-staticโ enables DEC-style STATIC and AUTOMATIC attributes so you can explicitly specify the storage of variables and other objects.-fdec-includeโ enables parsing of INCLUDE as a statement, in addition to parsing it as an INCLUDE line. When it's parsed as an INCLUDE statement, INCLUDE doesn't have to sit on a single line and can use line continuations. glow up โจ-fdec-format-defaultsโ enables the format specifiers F, G and I to be used without width specifiers โ default widths get used instead.-fdec-blank-format-itemโ enables a blank format item at the end of a format specification, i.e. nothing following the final comma. iconic, honestly.-fdollar-okโ allows$as a valid non-first character in a symbol name. Symbols that start with$are rejected, because it's genuinely unclear which rules to apply to implicit typing โ different vendors implement different rules. Using$inIMPLICITstatements is rejected too. rules are rules ๐-fbackslashโ changes how backslashes in string literals are interpreted: from a single backslash character into "C-style" escape characters. These combinations get expanded:\a,\b,\f,\n,\r,\t,\v,\\, and\0โ into the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. On top of that,\xnn,\unnnn and\Unnnnnnnn (where each n is a hexadecimal digit) are translated into the Unicode characters corresponding to the specified code points. Every other combination of a character preceded by\stays unexpanded. no cap ๐ฆ-fmodule-privateโ sets the default accessibility of module entities toPRIVATE. Use-associated entities won't be accessible unless they're explicitly declared asPUBLIC. shy module energy ๐-ffixed-line-length-nโ sets the column after which characters get ignored in typical fixed-form lines in the source file, and โ unless-fno-pad-sourceโ the column through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines.
popular values for n include 72 (the standard and the default), 80 (card image), and 132 (which corresponds to "extended-source" options in some popular compilers). n can also be none, meaning the entire line is meaningful and that continued character constants never have implicit spaces appended to them to fill out the line. and -ffixed-line-length-0 means the exact same thing as -ffixed-line-length-none. same girl, different name ๐
(more of this page is coming bestie, don't go anywhere ๐ซถ)
-fno-pad-sourceโ so like, by default, fixed-form lines get spaces assumed at the end (as if they were padded out to that length) when they're short. That padding does not happen if you use-ffixed-line-length-0,-ffixed-line-length-none, or this flag right here. And with any of those options, continued character constants never get implicit spaces tacked onto them to fill out the line. periodt ๐-ffree-line-length-nโ sets the column after which characters get ignored in your typical free-form lines. Default is132.ncan benone, which means the entire line matters. And-ffree-line-length-0means the exact same thing as-ffree-line-length-none. ๐-fmax-identifier-length=nโ caps how long an identifier is allowed to be. Typical values:31(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 slappingimplicit noneat the start of every procedure. iconic. โจ-fcray-pointerโ turns on the Cray pointer extension, which gives 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>. This option implies-pthread, so it's only supported on targets that support-pthread. Also-fopenaccimplies-frecursive. ๐ฅ-fopenmpโ enables handling of OpenMP directives!$ompin Fortran. It also enables the conditional compilation sentinel!$in Fortran. In fixed source form Fortran, the 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 support-pthread. And-fopenmpimplies-fopenmp-simdand-frecursive. ๐-fopenmp-allocatorsโ enables handling of allocation, reallocation and deallocation of Fortran allocatable and pointer variables that were allocated using the!$omp allocatorsand!$omp allocateconstructs. Files containing either directive have to be compiled with this option in addition to-fopenmp. Also, every file that might deallocate or reallocate a variable that's been allocated with an OpenMP allocator has to be compiled with this option too. That includes intrinsic assignment to allocatable variables when reallocation may occur, and deallocation due to any of these: end of scope, explicit deallocation,intent(out), deallocation of allocatable components, etc. Files that don't change the allocation status, or that only touch components of a derived type that were not 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. ๐ญ-fopenmp-simdโ enables handling of OpenMP'ssimd,declare simd,declare reduction,assume,ordered,scanandloopdirective, plus combined or composite directives withsimdas a constituent with!$ompin Fortran. It also enables the conditional compilation sentinel!$in Fortran. In fixed source form Fortran, the sentinels can also start withcor*. Other OpenMP directives are just ignored. 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 will give you an error at compile time when simplifyinga = 1. / 0. With this option, no error, andagets assigned the value+Infinity. If an expression evaluates to a value outside the relevant range of [-HUGE():HUGE()], then the expression gets replaced by-Infor+Infas appropriate. Same energy withDATA i/Z'FFFFFFFF'/โ that'll result in an integer overflow on most systems, but with-fno-range-checkthe value will "wrap around" andiwill be initialized to-1instead. wild. ๐-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. 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 like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-10,fdefault-real-10does not promote variables with explicit kind declarations.-fdefault-real-16โ sets the default real type to an 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 withfdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations.-fdefault-double-8โ sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8 byte wide type. 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 to anINTEGER(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โ these promote allREAL(KIND=M)entities toREAL(KIND=N)entities. IfREAL(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 affect 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 of4or8, 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. Also 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. ๐ญ-std=std โ specify 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 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,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 is only present for backwards compatibility with earlier gfortran versions and should not be used any more. ๐-ftest-forall-tempโ enhances test coverage by forcing most forall assignments to use temporary. ๐
โจ Enable and customize preprocessing โจ
Okay bestie so, listen: lots of Fortran compilers โ GNU Fortran included โ let you pipe your source code through a C preprocessor (CPP, sometimes called the Fortran preprocessor, FPP) so you can do conditional compilation. In GNU Fortran's case, it's the GNU C Preprocessor running in traditional mode. ๐
On systems with case-preserving file names, the preprocessor gets invoked automatically if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. ๐ฆ
Wanna manually invoke the preprocessor on any file? Use -cpp. Wanna disable preprocessing on files where it would otherwise run automatically? Use -nocpp. slay. โจ
Okay so bestie, 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" instead. No cap.
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 addition 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โ 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.-nocppโ 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
will show 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 will let the compiler know the current working directory at the time of preprocessing. When this option is enabled, 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 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"="will be 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"="will be 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"="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 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 will be 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 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#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 will be sent to a program which 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 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 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โ 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โ Issue warnings for uses of extensions to Fortran.-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 fine whether or not you use this option. But lowkey, without it, certain GNU extensions and traditional Fortran features are also allowed. Turn it on and a lot of those get rejected, no cap.
Some people try to use -pedantic to check whether their programs are actually conforming. Bestie, they find out real quick that it doesn't quite do 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 together with -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023.
-pedantic-errorsโ Same energy as-pedantic, except it produces errors instead of warnings. Like, it's not playing around anymore. ๐-Wallโ Turns on the commonly used warning options about usage that we recommend avoiding and that we genuinely believe is easy to avoid. Currently this includes-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop.-Waliasingโ Warns about possible aliasing of dummy arguments. Specifically, it yells at you 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, bestie:
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. This warning is given with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-std=f2023. Heads up: when there's no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that kicked off the continuation. iykyk.-Warray-temporariesโ Warns about array temporaries that the compiler generates. That info is sometimes genuinely useful for optimization, so you can avoid those temporaries entirely. slay.-Wc-binding-typeโ Warns if a variable might not be C interoperable. Specifically, it warns if the variable was declared using an intrinsic type with default kind instead of using a kind parameter defined for C interoperability in the intrinsicISO_C_Bindingmodule. This option is implied by-Wall.-Wcharacter-truncationโ Warns when a character assignment is gonna truncate the assigned string. ๐ญ-Wline-truncationโ Warns when a source code line is about to get truncated. This option is implied by-Wall. For free-form source code, the default is-Werror=line-truncation, so truncations get reported as errors.-Wconversionโ Warns about implicit conversions that are likely to change the value of the expression after conversion. Implied by-Wall.-Wconversion-extraโ Warns about implicit conversions between different types and kinds. This option does not imply-Wconversion.-Wextraโ Enables some warning options for usages of language features that might be problematic. Currently this includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeโ Warns when using-ffrontend-loop-interchangeto perform loop interchanges.-Wimplicit-interfaceโ Warns if a procedure is called without an explicit interface. Note that this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units. ๐-Wimplicit-procedureโ Warns if a procedure is called that has neither an explicit interface nor has been declared asEXTERNAL.-Winteger-divisionโ Warns if a constant integer division truncates its result. For example,3/5evaluates to0. ๐-Wintrinsics-stdโ Warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (with-std) and treats it as anEXTERNALprocedure because of that. You can use-fall-intrinsicsto never trigger this behavior and always link to the intrinsic regardless of the selected standard.-Wno-overwrite-recursiveโ Doesn't warn when-fno-automaticis used with-frecursive. Recursion will be broken if the relevant local variables don't have the attributeAUTOMATICexplicitly declared. You can use this option to suppress the warning when you know for a fact that 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.-Wsurprisingโ Produces a warning when "suspicious" code constructs show up. Technically legal, but they usually mean somebody made a mistake. ๐ฉ
Currently this produces a warning under the following circumstances:
- An INTEGER SELECT construct has a CASE that can never be matched because its lower value is greater than its upper value.
- A LOGICAL SELECT construct has three CASE statements.
- A TRANSFER specifies a source that is 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โ 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 that-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018,-std=f2023and-Wall.-Wundefined-do-loopโ Warns if a DO loop with step either1or-1yields an underflow or an overflow during iteration of an induction variable of the loop. This option is 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 that case, an explicit interface orEXTERNALorINTRINSICdeclaration might be needed 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 and thus implicitly imports all public entities of the used module. not the vibes.-Wunused-dummy-argumentโ Warns about unused dummy arguments. This option is implied by-Wall.-Wunused-parameterโ Contrary to gcc's meaning of-Wunused-parameter, gfortran's implementation of this option does not warn about unused dummy arguments (see-Wunused-dummy-argument), but about unusedPARAMETERvalues.-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 warning off via-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationโ Warns if any calls to impure functions are eliminated by the optimizations enabled by the-ffrontend-optimizeoption. This option is 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 shows up 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. This option is implied by-Wextra.-Wtarget-lifetimeโ Warns if the pointer in a pointer assignment might be 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 if an array subscript inside a DO loop could lead to an out-of-bounds access, even if the compiler can't prove that the statement is actually executed. Like in 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. yeah. all of them. ๐
Some of these have no effect when compiling programs written in Fortran.
๐ Options for debugging your program ๐
GNU Fortran has various special options that are used for debugging your program. very demure, very mindful, very useful.
-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-originaland enabling debugging of the executable program by using-gor-ggdb3.-ffpe-trap=listโ okay so this one is your floating-point bug snitch ๐ต๏ธโ๏ธ. You give it alistof floating point exception traps to turn on. On most systems, if a floating point exception happens and the trap for that exception is enabled, aSIGFPEsignal gets sent and the program is aborted, which drops a core file that is genuinely useful for debugging. Thelistis a (possibly empty) comma-separated list of eithernone(to clear the set of exceptions to be trapped), or of these exceptions: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 exceptions is probably a good idea. ๐
If the option is used more than once in the command line, the lists will be joined: "ffpe-trap="list1 "ffpe-trap="list2 is equivalent to "ffpe-trap="list1,list2.
๐จ Not me warning you but: once an exception is enabled it cannot be disabled (there is no negative form), except by clearing all traps by specifying none. That's the whole loophole, bestie.
Many, if not most, floating point operations incur loss of precision due to rounding, and hence ffpe-trap=inexact is likely to be uninteresting in practice. ๐
By default no exception traps are enabled.
-ffpe-summary=listโ this one picks which floating-point exceptions get their flag status printed toERROR_UNITwhen you invokeSTOPandERROR STOP. Thelistcan be eithernone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (Go peek at-ffpe-trapfor a description of the exceptions, it's all there. ๐)
If the option is used more than once in the command line, only the last one will be used. no cap.
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 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 is also added to the list of directories to searched by anUSEstatement.
The default is the current directory.
-fintrinsic-modules-path dirโ this option specifies the location of pre-compiled intrinsic modules, if they are 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 is not doing a link step. ๐
-static-libgfortranโ on systems that providelibgfortranas a shared and a static library, this option forces the use of the static version. If no shared version oflibgfortranwas built when the compiler was configured, this option has no effect.-static-libquadmathโ on systems that providelibquadmathas a shared and a static library, this option forces the use of the static version. If no shared version oflibquadmathwas 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. Read the fine print, bestie, fr fr.
๐ฆ 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 forconversionon 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 which 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 forlengthare4and8. 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 forlengthis2147483639, 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 number 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 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 are used for debugging the GNU Fortran compiler. This is backstage-at-the-compiler energy, iykyk. ๐
-fdump-fortran-globalโ output 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.-fdump-fortran-optimizedโ output 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-fortran-originalโ output 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 which have only recently been added.-fdump-parse-treeโ output 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. This option is deprecated; use-fdump-fortran-originalinstead. ๐ซ-save-tempsโ store the usual "temporary" intermediate files permanently; name them as auxiliary output files, as specified described under GCC-dumpbaseand-dumpdir.
gfortran -save-temps -c foo.F90
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.
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. ๐ก
-fno-automaticโ treat 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 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โ generate code designed to be compatible with code generated by g77 and f2c.
okay so real talk: the calling conventions that g77 used (they were originally implemented in f2c, bestie, we been knew) require that functions returning the default REAL type actually return the C type double, and functions returning COMPLEX hand their values back through an extra argument in the calling sequence โ one that points to where the return value should get stored. Meanwhile, under the default GNU calling conventions, those functions just return their results like they would in GNU C: default REAL functions give you the C type float, and COMPLEX functions give you the GNU C type complex. Iconic, honestly.
Also, this option implies the -fsecond-underscore option โ unless -fno-second-underscore is explicitly requested. So no sneaky double-underscore business unless you asked for it, periodt.
This does not affect the generation of code that interfaces with the libgfortran library. She's minding her own business ๐
Caution: it is not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions. CallingCOMPLEXor defaultREALfunctions between program parts that were compiled with different calling conventions will break at execution time. ๐ Not a vibe.
Caution: this will break code which passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, because 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. That's it, that's the whole girl.
With -funderscoring in effect, GNU Fortran appends one underscore to external names. Why? To ensure compatibility with code produced by many UNIX Fortran compilers. Respect the elders ๐ซถ
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). It's giving "science experiment, proceed with caution" ๐งช
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. Debugging without the underscore jumpscare? We love to see it.
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. Runtime bug hunting arc, truly the worst arc.
In future versions of GNU Fortran we hope to improve naming and linking issues so that debugging always involves using the names as they appear in the source, even if the names as seen by the linker are mangled to prevent accidental linking between procedures with incompatible interfaces. Manifesting this for the devs โจ๐
-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 external names with no underscores. GNU Fortran also appends two underscores to internal names with underscores, to avoid naming collisions with external names. Two underscores where it counts, bestie ๐
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>โ pick your coarray flavor, boo:noneโ disable coarray support; using coarray declarations and image-control statements will produce a compile-time error. (This is the 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>โ turn on 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. Toggle-able, we stan a flexible queen.allโ enable all run-time test of-fcheck.array-tempsโ warns at run time when a temporary array had to be generated for passing an actual argument. 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 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. (old money, still valid, but she's on her way out)-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 the reference the source text cuts off right there, bestie, iykyk). 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 the 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. ๐
The negative form, -fno-tail-call-workaround or the 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. Your disk said "please no".
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. Stack queen behavior, just keep an eye on your limits ๐ธ-fpack-derivedโ tells GNU Fortran to pack derived type members as tightly as physically possible ๐ . Fair warning bestie: code compiled with this is likely to be incompatible with code compiled without it, and it might run slower. It's giving "cute but chaotic".-frepack-arraysโ okay so sometimes GNU Fortran passes assumed shape array sections via a descriptor that's describing a noncontiguous area of memory ๐ซ . This option adds code to the function prologue to repack that data into one contiguous block at runtime.
The payoff? Faster accesses to the array, slay โจ. The cost? It can introduce significant overhead to the function call, especially when the passed data is noncontiguous. Tradeoffs, bestie, tradeoffs.
-fshort-enumsโ this one exists purely for interoperability with C code compiled with the-fshort-enumsoption ๐ค. It makes GNU Fortran pick the smallestINTEGERkind that a given enumerator set will fit in, and then gives all its enumerators that kind. Matching energies fr fr.-finline-arg-packingโ when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size one, or as an argument to a procedure that doesn't have an explicit interface, the argument may have to be packed โ i.e. put into contiguous memory. Classic example, the call tofoohere:
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 gets performed by inline code ๐ง. That 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. And heads up: if the code contains a very large number of arguments that have to be packed, code size and also compilation time may become excessive ๐ญ. If that's the case, it may be better to disable this option. You can find instances of packing by using -Warray-temporaries.
-fexternal-blasโ this makesgfortrangenerate calls to BLAS functions for some matrix operations likeMATMUL, instead of using its own algorithms, as long as 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 get 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 can't be determined at compile time, because code for both cases gets 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โ allows indirect recursion by forcing all local arrays to be allocated on the stack ๐ซถ. This flag cannot be used together with-fmax-stack-var-size=or-fno-automatic.-finit-local-zero-finit-derived-finit-integer=n-finit-real=<zero|inf|-inf|nan|snan>-finit-logical=<true|false>-finit-character=nโ the-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(wherenis an ASCII character value) options.
With -finit-derived, components of derived type variables will be initialized according to these flags ๐. Components whose type is not covered by an explicit -finit-* flag will be 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 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 ๐.
Finally, note that enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables. (RIP to those warnings, they served their purpose ๐.)
-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 increases performance. 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. The same form of this option should be used for all files that share aCOMMONblock โ ๏ธ. To avoid potential alignment issues inCOMMONblocks, it is recommended to order objects from largest to smallest.-fno-protect-parensโ by default the parentheses in expressions are honored for all optimization levels, such that the compiler doesn't do any re-association ๐ง. Using-fno-protect-parensallows the compiler to reorderREALandCOMPLEXexpressions to produce faster code ๐ฅ. Note that for the re-association optimization-fno-signed-zerosand-fno-trapping-mathneed to be in effect. The 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 is either unallocated or has a different shape ๐. The option is enabled by default except when-std=f95is given. See also-Wrealloc-lhs.-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. 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.
๐ 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 ๐ซถ. That's it. That's the whole section. No hidden vibes, no secret env vars, it's giving "nothing to see here bestie".
๐ BUGS ๐
For instructions on reporting bugs, see <file:///usr/share/doc/gcc-14/README.Bugs> ๐ฎ. (Yes, it's a file path, not a link, we don't make the rules.)
๐ 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 fr fr ๐ธ.
๐ AUTHOR ๐
See the Info entry for gfortran for contributors to GCC and GNU Fortran. Iconic legends, all of them ๐.
โญ COPYRIGHT โญ
Copyright (c) 2004-2024 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 one shipped out as gcc-14, dated 2024-09-08, under the name GFORTRAN(1). Go forth and compile, you absolute main character โจ๐.
๐ฆ where this page comes from
- ubuntu noble: gfortran-14-mips-linux-gnu 14.2.0-4ubuntu2~24.04cross1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms