GFORTRAN(1)
๐ GFORTRAN ๐
okay bestie, this is the manual for the GNU Fortran compiler โ manual section 1, GNU fam. Pull up a chair, we're gonna read the whole thing together ๐ซถ
โจ NAME โจ
gfortran โ the GNU Fortran compiler. she compiles, she slays, she's iconic ๐
โจ SYNOPSIS โจ
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
ngl that's just the hits, not the deep cuts. Only the most useful options are listed up there โ the rest of them live further down this page. ๐
โจ DESCRIPTION โจ
So like. gfortran supports all the options that the gcc command supports. But this manual? This manual is only documenting the options that are specific to GNU Fortran, because the gcc ones already have their own whole manual and she's not about to plagiarize ๐
Every single GCC option and every single GNU Fortran option is accepted by gfortran and by gcc (and also by any other driver that got built at the same time, like g++) โ because the moment GNU Fortran joined the GCC distribution, all the relevant drivers started accepting GNU Fortran options too. it's giving "we're all in this together" energy fr fr ๐
And a lil heads up about option forms: sometimes options come in a positive and a negative form. The negative form of -ffoo would be -fno-foo. This manual only documents one of the two forms โ specifically whichever one is not the default. iykyk ๐
โจ OPTIONS โจ
Okay so here's the whole summary of every option that's specific to GNU Fortran, sorted by category ๐ The actual explanations live in the sections after this one. Buckle up babes, it's a lot.
๐ธ 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-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 ๐
these ones control the ~vibes~ of the Fortran dialect your compiler is willing to accept. Obsessed with how much control we have honestly ๐
-ffree-form-ffixed-form
These two set the layout your source file uses. Free form layout showed up in Fortran 90 (the new hotness โจ). Fixed form is what all the older Fortran programs traditionally used (the vintage aesthetic, respect it ๐). If you don't pick either one, the source form gets figured out from the file extension. No cap.
-fall-intrinsics
This one makes all the intrinsic procedures get accepted โ including the GNU-specific extensions. Super useful if you're using -std= to force standard compliance but you still want access to the full buffet of intrinsics gfortran has to offer ๐ Because of this, -Wintrinsics-std gets ignored, and no user-defined procedure that shares a name with an intrinsic will actually get called โ unless it's explicitly declared EXTERNAL. the more you know ๐ซ
-fallow-argument-mismatch
Some code out there has calls to external procedures where the call and the procedure definition just... don't match ๐ญ or where two different calls to the same thing don't match each other. That code is nonconforming, and normally it gets flagged with an error. This option degrades that error down to a warning โ and the only way to turn that warning off is by disabling all warnings via -w. Only a single occurrence per argument gets flagged by this warning. Also, -fallow-argument-mismatch is implied by -std=legacy.
Using this option is strongly discouraged. ๐ You can absolutely write standard-conforming code that accepts different types of arguments โ just use an explicit interface and TYPE(*). Do that instead, bestie, I'm begging.
-fallow-invalid-boz
A BOZ literal constant is only allowed in a limited number of contexts in standard conforming Fortran. This option degrades an error condition down to a warning, and lets a BOZ literal constant show up in places where the Fortran standard would otherwise be like "absolutely not" ๐ โ๏ธ
-fd-lines-as-code-fd-lines-as-comments
These enable special treatment for lines that begin with "d" or "D" in fixed form sources. Give it -fd-lines-as-code and those lines get treated as if the first column contained a blank. Give it -fd-lines-as-comments and they get treated as comment lines. Simple as ๐
-fdec
DEC compatibility mode, babes. This turns on extensions and other features that mimic the default behavior of older compilers (like DEC). These features are nonstandard and should be avoided at all costs. ๐ญ For the details on how GNU Fortran implements these extensions, go read the full documentation.
The other flags this switch turns on are: -fdollar-ok, -fcray-pointer, -fdec-char-conversions, -fdec-structure, -fdec-intrinsic-ints, -fdec-static, -fdec-math, -fdec-include, -fdec-blank-format-item, -fdec-format-defaults.
And if -fd-lines-as-code / -fd-lines-as-comments aren't set, then -fdec also sets -fd-lines-as-comments.
-fdec-char-conversions
Enables character literals to be used in assignments and DATA statements for non-character variables. Yes really ๐ธ
-fdec-structure
Enables DEC STRUCTURE and RECORD, plus UNION, MAP, and the dot (.) as a member separator (in addition to %). This is provided for compatibility only โ Fortran 90 derived types should be used instead wherever possible. the way that legacy code just refuses to die ๐ญ
-fdec-intrinsic-ints
Enables B/I/J/K kind variants of existing integer functions (like BIAND, IIAND, JIAND, etc...). For the complete list of intrinsics, go check out Intrinsic Procedures. ๐
-fdec-math
Obsolete flag. The whole point of this option was to enable legacy math intrinsics like COTAN and degree-valued trigonometric functions (like 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, respect her legacy ๐ซถ
-fdec-static
Enables DEC-style STATIC and AUTOMATIC attributes, so you can explicitly specify the storage of variables and other objects. Main character energy for your memory layout โจ
-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 โ it can use line continuations. glow up fr fr ๐ฆ
-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. Like, nothing following the final comma. Just vibes. ๐
-fdollar-ok
Allows $ as a valid non-first character in a symbol name. Symbols that start with $ get rejected though โ because it's unclear which rules to apply to implicit typing, since different vendors implement different rules. Using $ in IMPLICIT statements is rejected too. ๐
-fbackslash
Changes how backslashes in string literals get interpreted โ instead of being a single backslash character, they become "C-style" escape characters. The following combinations get expanded: \a, \b, \f, \n, \r, \t, \v, \\, and \0 โ which become 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) get translated into the Unicode characters corresponding to the specified code points. Every other combination of a character preceded by \ stays unexpanded. the range?? unmatched โจ
-fmodule-private
Sets the default accessibility of module entities to PRIVATE. Use-associated entities are not accessible unless they're explicitly declared as PUBLIC. we love a gatekeeper ๐
-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 is in play, it also sets the column through which spaces are assumed (as if the line got padded out 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 continued character constants never get implicit spaces appended to them to fill out the line. Also, -ffixed-line-length-0 means exactly the same thing as -ffixed-line-length-none. ๐
okay bestie that's part 1, there's more coming so don't go anywhere ๐
-fno-pad-sourceโ bestie, by default fixed-form lines have spaces assumed (like they're padded to that length) after the ends of short fixed-form lines. This does not happen if you use-ffixed-line-length-0,-ffixed-line-length-none, or-fno-pad-source. With any of those, continued character constants never get implicit spaces appended to fill out the line. ๐-ffree-line-length-nโ sets the column after which characters are ignored in typical free-form lines in the source file. Default is132.ncan benone, meaning the entire line is meaningful.-ffree-line-length-0means the same as-ffree-line-length-none. โจ-fmax-identifier-length=nโ specify the maximum allowed identifier length. Typical values are31(Fortran 95) and63(Fortran 2003 and later). ๐-fimplicit-noneโ says no implicit typing allowed, unless overridden by explicitIMPLICITstatements. Equivalent to addingimplicit noneto the start of every procedure. ๐ซ-fcray-pointerโ enable the Cray pointer extension, which gives you C-like pointer functionality. ๐-fopenaccโ enable 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 have support for-pthread. The option-fopenaccimplies-frecursive. ๐ฅ-fopenmpโ enable 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 it's only supported on targets that have support for-pthread.-fopenmpimplies-fopenmp-simdand-frecursive. ๐ฅ-fopenmp-allocatorsโ enables handling of allocation, reallocation and deallocation of Fortran allocatable and pointer variables that are allocated using the!$omp allocatorsand!$omp allocateconstructs. Files containing either directive have to be compiled with this option in addition to-fopenmp. Additionally, all files that might deallocate or reallocate a variable that has been allocated with an OpenMP allocator have to be compiled with this option. This 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 not changing the allocation status or only for components of a derived type that have not been allocated using those two directives do not need to be compiled with this option. Nor do files that handle such variables after they have been deallocated or allocated by the normal Fortran allocator. ๐ง-fopenmp-simdโ enable handling of OpenMP'ssimd,declare simd,declare reduction,assume,ordered,scanandloopdirective, and of combined or composite directives withsimdas 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 ignored. Unless-fopenmpis additionally specified, theloopregion binds to the current task region, independent of the specifiedbindclause. ๐ฏ-fno-range-checkโ disable range checking on results of simplification of constant expressions during compilation. For example, GNU Fortran gives an error at compile time when simplifyinga = 1. / 0. With this option, no error is given andais 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 valuewraps aroundandiis initialized to-1instead. ๐-fdefault-integer-8โ set 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โ set the default real type to an 8 byte wide type. This option also affects the kind of non-double real constants like1.0. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-8,DOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations. ๐-fdefault-real-10โ set the default real type to a 10 byte wide type. This option also affects the kind of non-double real constants like1.0. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-10,DOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-10,fdefault-real-10does not promote variables with explicit kind declarations. ๐-fdefault-real-16โ set the default real type to a 16 byte wide type. This option also affects the kind of non-double real constants like1.0. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-16,DOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations. ๐-fdefault-double-8โ set theDOUBLE PRECISIONtype and double real constants like1.d0to an 8 byte wide type. Do nothing if this is already the default. This option prevents-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes. ๐-finteger-4-integer-8โ promote allINTEGER(KIND=4)entities toINTEGER(KIND=8)entities. IfKIND=8is unavailable, then an error is issued. This option should be used with care and may not be suitable for your codes. Areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. Inspection of the intermediate representation of the translated Fortran code, produced by-fdump-tree-original, is suggested. โ ๏ธ-freal-4-real-8,-freal-4-real-10,-freal-4-real-16,-freal-8-real-4,-freal-8-real-10,-freal-8-real-16โ promote 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 is also applied to real literal constants of default and double-precision kind and a specified kind number of 4 or 8, respectively. However,-fdefault-real-8,-fdefault-real-10,-fdefault-real-10, and-fdefault-double-8take precedence for the default and double-precision real kinds, both for real literal constants and for declarations without a kind number. Note that forREAL(KIND=KIND(1.0))the literal may get promoted and then the result may get promoted again. These options should be used with care and may not be suitable for your codes. Areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O and calls to intrinsic procedures when passing a value to thekind=dummy argument. Inspection of the intermediate representation of the translated Fortran code, produced by-fdump-fortran-originalor-fdump-tree-original, is suggested. NOTE: These options are incompatible with user defined derived type I/O (DTIO). ๐จ-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 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 is only present for backwards compatibility with earlier gfortran versions and should not be used any more.-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โ enhance test coverage by forcing most forall assignments to use temporary. ๐งช-funsignedโ allow the experimental unsigned extension. ๐ง
โจ Enable and customize preprocessing โจ
Okay bestie, this is the part where things get spicy ๐ซถ so many Fortran compilers out here โ GNU Fortran included โ let you run your source code through a C preprocessor (CPP, aka the Fortran preprocessor, aka FPP, iykyk) so you can do conditional compilation. With GNU Fortran specifically, it's the GNU C Preprocessor running in traditional mode. ๐
On systems with case-preserving file names, the preprocessor gets auto-invoked when the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. Wanna manually run the preprocessor on any file? That's -cpp. Wanna disable preprocessing on files where it would normally happen automatically? That's -nocpp, periodt.
When you're compiling a file that's already been preprocessed, use -fpreprocessed. It skips the C preprocessor entirely, no cap.
Heads up tho: if a preprocessed file pulls in another file with the Fortran INCLUDE statement, that included file does not get preprocessed. ๐ญ If you want the included files preprocessed too, use the equivalent preprocessor statement #include instead.
When GNU Fortran invokes the preprocessor, __GFORTRAN__ gets defined. You can use the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to figure out the version of the compiler. See Top,,Overview,cpp,The C Preprocessor for all the details. โจ
GNU Fortran also supports a whole bunch of INTEGER and REAL kind types on top of the kind types the Fortran standard requires. Whether any given kind type is available depends on your architecture, so vibe check accordingly. The following predefined preprocessor macros let you conditionally include code for these extra kind types: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__. ๐
And like, while CPP is the de facto standard for preprocessing Fortran code, Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines something called Conditional Compilation โ but it's not widely used and the GNU Fortran compiler doesn't directly support it. ๐
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 runs 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. ๐ฆ-idirafterdir โ Search dir for include files, but do it after all directories specified with-Iand the standard system directories have been exhausted. dir is treated as a system include directory. If dir begins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-imultilibdir โ Use dir as a subdirectory of the directory containing target-specific C++ headers.-iprefixprefix โ Specify prefix as the prefix for subsequent-iwithprefixoptions. If the prefix represents a directory, you should include the final/. ๐-isysrootdir โ This option is like the--sysrootoption, but applies only to header files. See the--sysrootoption for more information.-iquotedir โ Search dir only 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. If dir begins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-isystemdir โ Search dir for header files, after all directories specified by-Ibut before the standard system directories. Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. If dir begins 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 predicate predicate and answer answer. This form is preferred to the older form-Apredicate(answer), which is still supported, because it does not use shell special characters. ๐ซถ-A-predicate=answerโ Cancel an assertion with the predicate predicate and answer answer.-Cโ Do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive.
You should be prepared for side effects when using -C; it causes the preprocessor to treat comments as tokens in their own right. For example, comments appearing at the start of what would be a directive line have the effect of turning that line into an ordinary source line, since the first token on the line is no longer a #.
Warning: this currently handles C-Style comments only. The preprocessor does not yet recognize Fortran-style comments. ๐
-CCโ Do not discard comments, including during macro expansion. This is like-C, except that comments contained within macros are also passed through to the output file where the macro is expanded.
In addition to the side-effects of the -C option, the -CC option causes all C++-style comments inside a macro to be converted to C-style comments. This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line. The -CC option is generally used to support lint comments.
Warning: this currently handles C- and C++-Style comments only. The preprocessor does not yet recognize Fortran-style comments. ๐ญ
-Dnameโ Predefine name as a macro, with definition1.-Dname=definitionโ The contents of definition are tokenized and processed as if they appeared during translation phase three in a#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 of name, either built in or provided with a-Doption. ๐
๐ค Options to request or suppress errors and warnings ๐ค
Okay so let's talk diagnostics, bestie, because there are two whole flavors:
Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler keeps processing the program in an attempt to report further errors to aid in debugging, but it 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 to n, at which point GNU Fortran bails out rather than attempting to continue processing the source code. If n is0, there is no limit on the number of error messages produced. ๐-fsyntax-onlyโ bestie, this is the vibe check ๐ซถ It checks your code for syntax errors and then just... doesn't compile it. Like, it read the whole thing and has notes, but no output. Except: it still generates module files for every module in your code. No other output file though. Periodt.-Wpedantic,-pedanticโ issues warnings whenever you use extensions to Fortran. And-pedanticalso applies to C-language constructs where they show up in GNU Fortran source files, like using\ein a character constant inside a directive like"#include".
Valid Fortran programs should compile properly with or without this option. But heads up: without it, certain GNU extensions and traditional Fortran features are supported too. With it, many of them get rejected. ๐
Some users try to use -pedantic to check programs for conformance. They soon find that it does not do quite what they want โ it finds some nonstandard practices, but not all. That said, improvements to GNU Fortran in this area are welcome. ๐ซถ
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023.
-pedantic-errorsโ same energy as-pedantic, except errors are produced instead of warnings. so it's giving consequences โจ-Wallโ turns on the commonly used warning options, the ones about usage that we recommend avoiding and that we believe are 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 warns if the same actual argument is associated with a dummy argument withINTENT(IN)and a dummy argument withINTENT(OUT)in a call with an explicit interface.
The following example 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. This warning shows up with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-std=f2023. Note: with no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that initiated the continuation.-Warray-temporariesโ warns about array temporaries generated by the compiler. The info this warning gives you is sometimes useful in optimization, so you can avoid such temporaries. ๐ง-Wc-binding-typeโ warns if the a variable might not be C interoperable. In particular, warn if the variable has been declared using an intrinsic type with default kind instead of using a kind parameter defined for C interoperability in the intrinsic"ISO_C_Binding"module. This option is implied by-Wall.-Wcharacter-truncationโ warns when a character assignment truncates the assigned string. ๐ญ-Wline-truncationโ warns when a source code line is truncated. This option is implied by-Wall. For free-form source code, the default is-Werror=line-truncationsuch that truncations are reported as error.-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.-Wdeprecated-openmpโ warns for usage of deprecated OpenMP code. โ ๏ธ-Wexternal-argument-mismatchโ warns about argument mismatches for dummy external procedures. This is implied by-fc-prototypes-externalbecause generation of a valid C23 interface is not possible in such a case. Also implied by-Wall.-Wextraโ enables some warning options for usages of language features that may be problematic. Currently this includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeโ warns when using-ffrontend-loop-interchangefor performing loop interchanges.-Wimplicit-interfaceโ warns if a procedure is called without an explicit interface. Note this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units. ๐-Wimplicit-procedureโ warns if a procedure is called that has neither an explicit interface nor has been declared as"EXTERNAL".-Winteger-divisionโ warns if a constant integer division truncates its result. As an example,3/5evaluates to0.-Wintrinsics-stdโ warns if gfortran finds a procedure named like an intrinsic not available in the currently selected standard (with-std) and treats it as"EXTERNAL"procedure because of this.-fall-intrinsicscan be used to never trigger this behavior and always link to the intrinsic regardless of the selected standard.-Wno-overwrite-recursiveโ do not warn when-fno-automaticis used with-frecursive. Recursion is broken if the relevant local variables do not have the attribute"AUTOMATIC"explicitly declared. This option can be used to suppress the warning when it is known that recursion is not broken. Useful for build environments that use-Werror. ๐ ๏ธ-Wreal-q-constantโ produces a warning if a real-literal-constant contains a"q"exponent-letter.-Wsurprisingโ produces a warning when"suspicious"code constructs are encountered. While technically legal, these usually indicate that an error has been made. ๐
This currently produces a warning under the following circumstances:
- An
"INTEGER"-typed"SELECT CASE"construct has a"CASE"that can never be matched as its lower value is greater than its upper value. - A
"LOGICAL"-typed"SELECT CASE"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
"CHARACTER"variable is declared with negative length. - With
-fopenmp, for fixed-form source code, when an"omx"vendor-extension sentinel is encountered. (The equivalent"ompx", used in free-form source code, is diagnosed by default.) - With
-fopenacc, when using named constances with clauses that take a variable as 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 between 1 and 9 is supported.-Wtabscauses a warning to be issued if 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 a"DO"loop with step either 1 or -1 yields 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 that yield an underflow are encountered during compilation. Enabled by default.-Wintrinsic-shadowโ warns if a user-defined procedure or module procedure has the same name as an intrinsic; in this case, an explicit interface or"EXTERNAL"or"INTRINSIC"declaration might be needed to get calls later resolved to the desired intrinsic/procedure. This option is implied by-Wall. ๐ฆ-Wuse-without-onlyโ warns if a"USE"statement has no"ONLY"qualifier and thus implicitly imports all public entities of the used module.-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 unused"PARAMETER"values.-Wunused-parameteris implied by-Wextraif also-Wunusedor-Wallis used.-Walign-commonsโ by default, gfortran warns about any occasion of variables being padded for proper alignment inside a"COMMON"block. This warning can be turned 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 to 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 the performance. If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g."(:,:,:)") for the variable on the left-hand side to prevent the reallocation check. Note that in some cases the warning is shown, even if the compiler optimizes 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 to 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 the its target. This option is implied by-Wall.-Wzerotripโ warns if a"DO"loop 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 cannot prove that the statement is actually executed, in cases like
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 bestie", everything is a problem now ๐ญ๐
Some of these have zero effect when you're compiling programs that were written in Fortran. Just so you know. ๐
โจ Options for debugging your program โจ
GNU Fortran has a whole lil collection of special options that exist purely to help you debug your program. Besties, they're so useful.
-fdebug-aux-varsโ Renames the internal variables that the gfortran front end creates, so a debugger can actually see them. The internal variable names then start with uppercase letters followed by an underscore. This is the move when you're debugging the compiler's code generation together with-fdump-tree-original, and also when you want to debug the executable program itself using-gor-ggdb3. ๐- *
-ffpe-trap=list* โ Specify a list of floating point exception traps to enable. On most systems, if a floating point exception happens and the trap for that exception is enabled, aSIGFPEsignal gets sent and the program gets aborted, which produces a core file that's useful for debugging. list is a (possibly empty) comma-separated list of eithernone(to clear the whole 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 line up with 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 mean 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 get joined: -ffpe-trap=list1 -ffpe-trap=list2 is equivalent to -ffpe-trap=list1,list2.
Heads up bestie: once an exception is enabled, it cannot be disabled (there's 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 -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 you invokeSTOPandERROR 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. 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 it's 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 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 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 isn't doing a link step.
-static-libgfortranโ On systems that provide libgfortran as 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 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, bestie: 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, fr fr. ๐
๐ Influencing runtime behavior ๐
These options affect the runtime behavior of programs compiled with GNU Fortran. So iconic of them.
- *
-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 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. (Yes, debugging the compiler itself. Main character energy.)
-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 that 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 that 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 that 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 that have only recently been added.
This option is deprecated; use -fdump-fortran-original instead. ๐
-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 list 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. iykyk โจ
-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โ bestie, this one makes your code play nice with stuff compiled byg77andf2c๐. The calling conventions fromg77(originally fromf2c) are a whole different vibe: functions that return defaultREALactually return the C typedouble, and functions that returnCOMPLEXreturn their values via an extra argument in the calling sequence that points to where to store the return value. Under the default GNU calling conventions, those functions just return their results like they would in GNU C โ defaultREALfunctions return the C typefloat, andCOMPLEXfunctions return the GNU C typecomplex. Also, this option implies-fsecond-underscoreunless you explicitly ask for-fno-second-underscore. It does not affect code that interfaces with thelibgfortranlibrary. โจ
Caution: mixing Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions is not a good idea, because callingCOMPLEXor defaultREALfunctions between program parts compiled with different calling conventions will break at execution time. ๐
Caution: this also breaks code that passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, because the library implementations use the-fno-f2ccalling conventions. ๐ญ
-fno-underscoringโ okay so this one says don't add underscores to the names of entities in your Fortran source file. ๐ธ With-funderscoringin effect, GNU Fortran appends one underscore to external names, which is done to keep things compatible with code from many UNIX Fortran compilers. But heads up: this does not apply to names declared with C binding or names within a module. ๐
Caution: the default behavior of GNU Fortran is incompatible withf2candg77, so please use the-ff2coption if you want object files compiled with GNU Fortran to be compatible with object code from those tools. ๐ซถ
Using -fno-underscoring is not recommended unless you're out here experimenting with stuff like integrating GNU Fortran into existing system environments (vis-ร -vis existing libraries, tools, and so on). ๐
For example, with -funderscoring, and assuming 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, that same statement becomes:
i = j() + max_count(&my_var, &lvar);
Using -fno-underscoring lets you directly specify user-defined names while debugging and when interfacing GNU Fortran code with other languages. But bestie, just because names match does not mean the interface implemented by GNU Fortran for an external name matches the interface implemented by some other language for that same name. Like, 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 from 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, 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. ๐
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 in this section. ๐
-fsecond-underscoreโ by default, GNU Fortran appends an underscore to external names. With this option, GNU Fortran appends two underscores to names that already have underscores and one underscore to names with no underscores. So an external name likeMAX_COUNTbecomes a reference to the link-time external symbolmax_count__instead ofmax_count_. This is required for compatibility withg77andf2c, and it's implied by using-ff2c. This option has no effect if-fno-underscoringis in effect. It is implied by the-ff2coption. โจ-fcoarray=<keyword>โ coarrays, bestie! The keyword can be:noneโ Disable coarray support; using coarray declarations and image-control statements produces a compile-time error. (This is the default.) ๐ซsingleโ Single-image mode, i.e.num_images()is always one. 1๏ธโฃsharedโ Use shared-memory multithreading parallelization. ๐งตlibโ Library-based coarray parallelization; you need to link a suitable GNU Fortran coarray library such as <http://opencoarrays.org>. Alternatively, GCC'slibcaf_singlelibrary can be linked, albeit it only supports a single image. ๐
-fcheck=<keyword>โ enable 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 tests of-fcheck. โarray-tempsโ Warns at run time when, for passing an actual argument, a temporary array had to be generated. The info from this warning is sometimes useful in optimization to avoid such temporaries. Note: the warning is only printed once per location. โ ๏ธbitsโ Enable generation of run-time checks for invalid arguments to the bit manipulation intrinsics. ๐ขboundsโ Enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds and ensures that all string lengths are equal for character array constructors without an explicit typespec. Some checks require that-fcheck=boundsis set for the compilation of the main program. Note: in the future this may also include other forms of checking, e.g., checking substring references. ๐doโ Enable generation of run-time checks for invalid modification of loop iteration variables. ๐memโ Enable generation of run-time checks for memory allocation. Note: this option does not affect explicit allocations using 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. ๐ซ-ftail-call-workaround,-ftail-call-workaround=nโ okay so 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=2tail call optimization is disabled in all gfortran procedures with character arguments, with-ftail-call-workaround=1or equivalent-ftail-call-workaroundonly 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. โณ The negative form, -fno-tail-call-workaround or equivalent -ftail-call-workaround=0, can be used to disable this option. Default is currently -ftail-call-workaround, this will change in future releases. ๐ฎ
-fcheck-array-temporariesโ Deprecated alias for-fcheck=array-temps. ๐ซ-fmax-array-constructor=nโ This option can increase the upper limit permitted in array constructors. The code below requires this option to expand the array at compile time. ๐
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
Caution: This option can lead to long compile times and excessively large object files. ๐
The default value for n is 65535. ๐ข
-fmax-stack-var-size=nโ This option specifies the size in bytes of the largest array that is 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 that 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 fornis65536. ๐ข-fstack-arraysโ bestie, this one puts every array of unknown size plus all the array temporaries onto stack memory ๐ . If your program is out here using very large local arrays, you might have to go extend your runtime limits for stack memory on some operating systems, no cap. It's switched on 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 tho: code compiled with this option is likely to be incompatible with code compiled without it ๐ญ, and it may execute slower. It's giving risky glow-up.-frepack-arraysโ so sometimes GNU Fortran passes 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 ๐. Trade-off queen fr.
-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 gives all its enumerators this kind. Efficient little icon โจ.-finline-arg-packingโ when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size thing, or as an argument to a procedure that doesn't 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 makesgfortrangenerate 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โ makesgfortrangenerate 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 bygfortraninternal 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<br>*-finline-intrinsics=intr1*,intr2,... โ prefer generating inline code over calls tolibgfortranfunctions 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๐ซ.-finit-local-zero<br>-finit-derived<br>-finit-integer=n<br>-finit-real=<zero|inf|-inf|nan|snan><br>-finit-logical=<true|false><br>-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 (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โ 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 expression are honored for all optimization levels such that the compiler does not do any reassociation ๐ซถ. Using-fno-protect-parensallows the compiler to reorderREALandCOMPLEXexpressions to produce faster code โก. Note that for the reassociation 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 is only 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
- And if you're like "no thank you bestie"? you deselect it by specifying
-fno-frontend-optimize๐ -ffrontend-loop-interchangeโ ok so this one tries to interchange loops right there in the Fortran front end, but only where profitable ๐ค. It's enabled by default by any-Ooption โจ. RN it only touchesFORALLandDO CONCURRENTstatements that have several forall triplets โ that's the whole vibe, no cap ๐
๐ฟ ENVIRONMENT ๐ฟ
So here's the tea: gfortran currently does not use any environment variables to control how it operates, beyond the ones that already affect how gcc operates ๐ซถ. That's it. That's the section. Nothing sneaky hiding in your shell config, bestie ๐
๐ BUGS ๐
Need to report a bug? The instructions live at <http://bugzilla.redhat.com/bugzilla> โ go tell them everything, they want to know ๐ (fr fr, bug reports are how software gets better)
๐ SEE ALSO ๐
Go read these too, they're all part of the family:
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,binutilsandgdb๐
๐ AUTHOR ๐
See the Info entry for gfortran for contributors to GCC and GNU Fortran. Shoutout to every single one of them, genuinely iconic behavior ๐ซก๐
๐ 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 on the whole page, bestie!! ๐ This was gcc-16.2.1, dated 2026-08-19, and you just read the one and only GFORTRAN(1) ๐โจ Go compile something cute, you absolute legend ๐ฆ๐
๐ฆ where this page comes from
- fedora 44: ucrt64-gcc-gfortran 16.2.1-1.fc44 ยท GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms