GFORTRAN(1)
π GFORTRAN(1) π β okay bestie, it's the GNU Fortran compiler page, and we're doing this together π
GFORTRAN(1) β the GNU manual, section 1. Periodt. No cap.
πΈ NAME πΈ
gfortran β the GNU Fortran compiler. That's it. That's the name. Iconic.
β¨ SYNOPSIS β¨
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
Only the most useful options are listed here; see below for the remainder. Yes, there are more. So many more. We're getting to them, I promise. π«Ά
π¦ DESCRIPTION π¦
So the gfortran command supports all the options supported by the gcc command. Only the options that are specific to GNU Fortran are documented here β the rest are giving "go ask gcc, she knows" energy. π
All GCC and GNU Fortran options are accepted both by gfortran and by gcc (as well as any other drivers built at the same time, such as g++), since adding GNU Fortran to the GCC distribution enables acceptance of GNU Fortran options by all of the relevant drivers. They're all in the same group chat, basically. β¨
In some cases, options have positive and negative forms; the negative form of -ffoo would be -fno-foo. This manual documents only one of these two forms, whichever one is not the default. So if you were like "where's the other one", bestie, it's the default. That's the whole thing. π
π OPTIONS π
Here is a summary of all the options specific to GNU Fortran, grouped by type. Explanations are in the following sections. Buckle up, babe. π
π 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 π
The following options control the details of the Fortran dialect accepted by the compiler. Yes, the dialect. It's giving linguistics major but make it compiler. π
-ffree-form-ffixed-formβ Specify the layout used by the source file. The free form layout was introduced in Fortran 90. Fixed form was traditionally used in older Fortran programs. When neither option is specified, the source form is determined by the file extension. So like, the file extension is the vibe check. π-fall-intrinsicsβ This option causes all intrinsic procedures (including the GNU-specific extensions) to be accepted. This can be useful with-std=to force standard-compliance but get access to the full range of intrinsics available withgfortran. As a consequence,-Wintrinsics-stdwill be ignored and no user-defined procedure with the same name as any intrinsic will be called except when it is explicitly declared"EXTERNAL". Okay so it's giving "I want the standard and the secret menu". π-fallow-argument-mismatchβ Some code contains calls to external procedures with mismatches between the calls and the procedure definition, or with mismatches between different calls. Such code is non-conforming, and will usually be flagged with an error. This options degrades the error to a warning, which can only be disabled by disabling all warnings via-w. Only a single occurrence per argument is flagged by this warning.-fallow-argument-mismatchis implied by-std=legacy.
Using this option is strongly discouraged. It is possible to provide standard-conforming code which allows different types of arguments by using an explicit interface and TYPE(*).
So like, she works, but she's messy. Don't. π
-fallow-invalid-bozβ A BOZ literal constant can occur in a limited number of contexts in standard conforming Fortran. This option degrades an error condition to a warning, and allows a BOZ literal constant to appear where the Fortran standard would otherwise prohibit its use. It's the "technically not allowed but go off" option. π-fd-lines-as-code-fd-lines-as-commentsβ Enable special treatment for lines beginning with"d"or"D"in fixed form sources. If the-fd-lines-as-codeoption is given they are treated as if the first column contained a blank. If the-fd-lines-as-commentsoption is given, they are treated as comment lines. Choose your fighter. π-fdecβ DEC compatibility mode. Enables extensions and other features that mimic the default behavior of older compilers (such as DEC). These features are non-standard and should be avoided at all costs. For details on GNU Fortran's implementation of these extensions see the full documentation.
Other flags enabled by this switch are: -fdollar-ok -fcray-pointer -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints -fdec-static -fdec-math -fdec-include -fdec-blank-format-item -fdec-format-defaults
If -fd-lines-as-code/-fd-lines-as-comments are unset, then -fdec also sets -fd-lines-as-comments.
"Avoided at all costs" is a direct quote, bestie. This is not a drill. π
-fdec-char-conversionsβ Enable the use of character literals in assignments and"DATA"statements for non-character variables. Chaotic but historical. π-fdec-structureβ Enable DEC"STRUCTURE"and"RECORD"as well as"UNION","MAP", and dot (.) as a member separator (in addition to%). This is provided for compatibility only; Fortran 90 derived types should be used instead where possible. It's giving vintage. π¦-fdec-intrinsic-intsβ Enable B/I/J/K kind variants of existing integer functions (e.g. BIAND, IIAND, JIAND, etc...). For a complete list of intrinsics see the full documentation. So many letters. π₯-fdec-mathβ Obsolete flag. The purpose of this option was to enable legacy math intrinsics such as COTAN and degree-valued trigonometric functions (e.g. TAND, ATAND, etc...) for compatability 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, but we still respect her. π-fdec-staticβ Enable DEC-style STATIC and AUTOMATIC attributes to explicitly specify the storage of variables and other objects. Very "I choose where you live" energy. π-fdec-includeβ Enable parsing of INCLUDE as a statement in addition to parsing it as INCLUDE line. When parsed as INCLUDE statement, INCLUDE does not have to be on a single line and can use line continuations. She's flexible now. β¨-fdec-format-defaultsβ Enable format specifiers F, G and I to be used without width specifiers, default widths will be used instead. The compiler will pick for you. Trust. π«Ά-fdec-blank-format-itemβ Enable a blank format item at the end of a format specification i.e. nothing following the final comma. The comma at the end is just there. And that's valid now. π-fdollar-okβ Allow$as a valid non-first character in a symbol name. Symbols that start with$are rejected since it is unclear which rules to apply to implicit typing as different vendors implement different rules. Using$in"IMPLICIT"statements is also rejected. So$can be in the name, just not at the front. Boundaries, bestie. π-fbackslashβ Change the interpretation of backslashes in string literals from a single backslash character to"C-style"escape characters. The following combinations are expanded"\a","\b","\f","\n","\r","\t","\v","\\", and"\0"to the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. Additionally,"\x"nn,"\u"nnnnand"\U"nnnnnnnn(where each n is a hexadecimal digit) are translated into the Unicode characters corresponding to the specified code points. All other combinations of a character preceded by\are unexpanded. Escape sequences are so main character. π-fmodule-privateβ Set the default accessibility of module entities to"PRIVATE". Use-associated entities will not be accessible unless they are explicitly declared as"PUBLIC". Default privacy settings: maximum. π-ffixed-line-length-nβ Set column after which characters are ignored in typical fixed-form lines in the source file, and, unless"-fno-pad-source", through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines.
Popular values for n include 72 (the standard and the default), 80 (card image), and 132 (corresponding to "extended-source" options in some popular compilers). n may also be none, meaning that the entire line is meaningful and that continued character constants never have implicit spaces appended to them to fill out the line. -ffixed-line-length-0 means the same thing as -ffixed-line-length-none.
Okay so72is the default,80is card image,132is extended-source, andnone/0means the whole line matters. Pick your length, babe. π
-fno-pad-sourceβ okay so by default, fixed-form lines get spaces assumed after the end of short fixed-form lines (like they got padded out to that length, bestie). That padding does not happen if you use-ffixed-line-length-0,-ffixed-line-length-none, or this very option-fno-pad-source. And with any of those, continued character constants never get implicit spaces appended to fill out the line. no sneaky invisible spaces, periodt β¨-ffree-line-length-nβ sets the column after which characters are ignored in typical free-form lines in the source file. Default is132. Andncan benone, meaning the whole entire line is meaningful (nothing gets yeeted). Also-ffree-line-length-0means the exact same thing as-ffree-line-length-none. π-fmax-identifier-length=nβ caps the maximum allowed identifier length. Typical values are31(Fortran 95) and63(Fortran 2003 and later). pick your era, bestie π-fimplicit-noneβ says nope, no implicit typing allowed, unless an explicitIMPLICITstatement overrides it. It's literally the equivalent of addingimplicit noneto the start of every procedure. the way that just fixes everything for you π-fcray-pointerβ turns on the Cray pointer extension, which gives you C-like pointer functionality. very vintage, very iconic π-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, and thus is only supported on targets that have support for-pthread. Also-fopenaccimplies-frecursive. π-fopenmpβ enables handling of OpenMP directives!$ompin Fortran. It additionally 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, and thus is only supported on targets that have support for-pthread. And-fopenmpimplies-fopenmp-simdand-frecursive. parallel besties fr fr π₯-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 that aren't changing the allocation status, or only do it 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. ngl this one's a whole group project, everyone's gotta show up π-fopenmp-simdβ enables handling of OpenMP'ssimd,declare simd,declare reduction,assume,ordered,scanandloopdirective, and of combined or composite directives withsimdas a constituent with!$ompin Fortran. It additionally enables the conditional compilation sentinel!$in Fortran. In fixed source form Fortran, the sentinels can also start withcor*. Other OpenMP directives are 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 an error at compile time when simplifyinga = 1. / 0. With this option, no error will be given andawill be assigned the value+Infinity. If an expression evaluates to a value outside of the relevant range of[-HUGE():HUGE()], then the expression will be replaced by-Infor+Infas appropriate. Similarly,DATA i/Z'FFFFFFFF'/will result in an integer overflow on most systems, but with-fno-range-checkthe value will "wrap around" andiwill be initialized to-1instead. chaos mode activated π-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. This option promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along withfdefault-real-8,DOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations. πΈ-fdefault-real-10β sets the default real type to an 10 byte wide type. This option also affects the kind of non-double real constants 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β sets the default real type to an 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β sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8 byte wide type. Does nothing if this is already the default. This option prevents-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16, from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes. π-finteger-4-integer-8β promotes 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.
bestie pls read that warning twice, this one is not a casual little toggle π
-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 will be issued. The-freal-4-flags also affect the default real kind and the-freal-8-flags also the double-precision real kind. All other real-kind types are unaffected by this option. The promotion is also applied to real literal constants of default and double-precision kind and a specified kind number 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. 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.
okay so double-promotion is real and it's lowkey unhinged. inspect that intermediate representation, bestie, don't just vibe and pray π
-std=stdβ specifies the standard to which the program is expected to conform, which may be one off95,f2003,f2008,f2018,f2023,gnu, orlegacy. The default value for std isgnu, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran, although warnings 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. cute little coverage booster π
π§ Enable and customize preprocessing π§
Many Fortran compilers including GNU Fortran allow passing the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) to allow for conditional compilation. In the case of GNU Fortran, this is the GNU C Preprocessor in the traditional mode. On systems with case-preserving file names, the preprocessor is automatically invoked if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. To manually invoke the preprocessor on any file, use -cpp; to disable preprocessing on files where the preprocessor is run automatically, use -nocpp. β¨
iykyk: uppercase extension = preprocessor said hi π
okay so if a preprocessed file pulls in another file with the Fortran INCLUDE statement, that included file does not get preprocessed π. If you want included files preprocessed too, use the equivalent preprocessor statement #include instead. slay.
If GNU Fortran invokes the preprocessor, __GFORTRAN__ gets defined β¨. And the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ are there so you can clock the version of the compiler you're dealing with. See Top,,Overview,cpp,The C Preprocessor for all the details, bestie.
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 even available is architecture dependent (iykyk). These pre-defined preprocessor macros let you conditionally include code for those 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 Conditional Compilation β which is not widely used and not directly supported by the GNU Fortran compiler π. If you need to preprocess that kind of file, you can use the program coco (<http://www.daniellnagle.com/coco.html>).
The following options control preprocessing of Fortran code:
-cpp,-nocppβ Enable preprocessing π. The preprocessor is automatically invoked if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08. Use this option to manually enable preprocessing of any kind of Fortran file. To disable preprocessing of files with any of those extensions, use the negative form:-nocpp. The preprocessor is run in traditional mode, so any restrictions of the file-format β especially the limits on line length β apply to preprocessed output as well, which means it might be advisable to use the-ffree-line-length-noneor-ffixed-line-length-noneoptions. π‘-dMβ Instead of the normal output, generate a list of'#define'directives 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"#define"directives 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'#undef'directives are also output for macros tested but undefined at the time. π-dIβ Output'#include'directives 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"#line"directives are emitted whatsoever. π-idirafterdir β Search dir for include files, but do it after all directories specified with-Iand the standard system directories have been exhausted. dir is treated as a system include directory. If dir begins with"=", then the"="will be replaced by the sysroot prefix; see--sysrootand-isysroot. π-imultilibdir β Use dir as a subdirectory of the directory containing target-specific C++ headers. π-iprefixprefix β Specify prefix as the prefix for subsequent-iwithprefixoptions. If the prefix represents a directory, you should include the final'/'. π-isysrootdir β This option is like the--sysrootoption, but 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"="will be replaced by the sysroot prefix; see--sysrootand-isysroot. β-isystemdir β Search dir for header files, after all directories specified by-Ibut before the standard system directories. Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. If dir begins with"=", then the"="will be replaced by the sysroot prefix; see--sysrootand-isysroot. πΈ-nostdincβ Do not search the standard system directories for header files. Only the directories you 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-A predicate(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-Coption, the-CCoption 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-CCoption is generally used to support lint comments. Warning: this currently handles C- and C++-Style comments only. The preprocessor does not yet recognize Fortran-style comments. π-Dnameβ Predefine name as a macro, with definition1. π-Dname=definitionβ The contents of definition are tokenized and processed as if they appeared during translation phase three in a'#define'directive. In particular, the definition will be truncated by embedded newline characters. If you 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. Withshandcsh,"-D'name(args...)=definition'"works. π-Dand-Uoptions are processed in the order they are given on the command line. All-imacrosfile and-includefile options are processed after all-Dand-Uoptions. π-Hβ Print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the'#include'stack it is. π-Pβ Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers. π¦-Unameβ Cancel any previous definition of name, either built in or provided with a-Doption. π«
π¨ Options to request or suppress errors and warnings π¨
Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code π. The compiler will continue to process the program in an attempt to report further errors to aid in debugging, but will not produce any compiled output. periodt.
Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there is likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. π«Ά
You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default. π
These options control the amount and kinds of errors and warnings produced by GNU Fortran:
-fmax-errors=nβ Limits the maximum number of error messages to n, at which point GNU Fortran bails out rather than attempting to continue processing the source code. If n is0, there is no limit on the number of error messages produced. π¨-fsyntax-onlyβ Check the code for syntax errors, but do not actually compile it. This will generate module files for each module present in the code, but no other output file. β¨-Wpedantic,-pedanticβ Issue warnings for uses of extensions to Fortran.-pedanticalso applies to C-language constructs where they occur in GNU Fortran source files, such as use of\ein a character constant within a directive like"#include". π
okay so bestie, valid Fortran programs should compile properly whether or not you use -pedantic. But here's the tea: without it, some GNU extensions and old-school Fortran features are still supported. With it, a lot of those get rejected. π
Some people try to use -pedantic to check if their code is conforming, but then they find out it doesn't do exactly what they wantβit catches some nonstandard stuff, but not all. Still, improvements to GNU Fortran in this area are welcome! π«Ά
This should be used together with -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023. Periodt.
-pedantic-errorsβ just like-pedantic, but instead of warnings, it throws errors. So it's the β¨dramaticβ¨ version.-Wallβ turns on a bunch of commonly used warnings about stuff we think you should avoid and that's easy to avoid. Currently includes:-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop. So many warnings, so little time. π-Waliasingβ warns you about possible aliasing of dummy arguments. Like, if the same actual argument is linked to a dummy argument withINTENT(IN)and another withINTENT(OUT)in a call with an explicit interface, it'll call you out. π
Here's an example that 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 missing ampersand in continued character constants. This warning shows up with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-std=f2023. Note: if you don't put an ampersand in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that started the continuation. So basically, it's got your back. π«Ά-Warray-temporariesβ warns about array temporaries that the compiler creates. Sometimes this info is useful for optimization so you can avoid those temporaries. π‘-Wc-binding-typeβ warns if a variable might not be C interoperable. Specifically, if it's declared with an intrinsic type with default kind instead of a kind parameter from theISO_C_Bindingmodule for C interoperability. This is implied by-Wall. So-Wallalready got you. π-Wcharacter-truncationβ warns when a character assignment is gonna truncate the string you're assigning. Not cute. π-Wline-truncationβ warns when a source code line is about to be truncated. Implied by-Wall. For free-form source code, the default is-Werror=line-truncationso truncations become errors. Yikes. π-Wconversionβ warns about implicit conversions that might change the value of the expression after conversion. Implied by-Wall. So watch out. π₯-Wconversion-extraβ warns about implicit conversions between different types and kinds. But note: this option does not imply-Wconversion. It's extra, but not that extra. πββοΈ-Wextraβ turns on some warning options for language features that might be problematic. Currently includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript. Extra, but make it fashion. π-Wfrontend-loop-interchangeβ warns when you use-ffrontend-loop-interchangeto do loop interchanges. Just a heads up. π-Wimplicit-interfaceβ warns if a procedure is called without an explicit interface. But note: it only checks that an explicit interface is present. It doesn't check if the declared interfaces are consistent across program units. So it's a vibe check, not a full background check. π-Wimplicit-procedureβ warns if you call a procedure that has no explicit interface and isn't declared asEXTERNAL. Basically, it's like, "who dis?" π-Winteger-divisionβ warns if a constant integer division truncates its result. For example,3/5evaluates to0. Math is mathing, but not in a good way. π-Wintrinsics-stdβ warns if gfortran finds a procedure named like an intrinsic that's not available in the currently selected standard (with-std) and treats it as anEXTERNALprocedure because of that. You can use-fall-intrinsicsto never trigger this and always link to the intrinsic regardless of the standard. So you can have your cake and eat it too. π°-Wno-overwrite-recursiveβ do not warn when-fno-automaticis used with-frecursive. Recursion will be broken if the relevant local variables don't have theAUTOMATICattribute explicitly declared. You can use this option to suppress the warning when you know recursion isn't broken. Super useful for build environments that use-Werror. So if you know, you know. π€«-Wreal-q-constantβ produces a warning if a real-literal-constant contains aqexponent-letter. Like, why is there a q? π-Wsurprisingβ produces a warning when it encounters "suspicious" code constructs. Even though they're technically legal, they usually mean you messed up. π¬
It currently warns in these situations:
- An
INTEGER SELECTconstruct has aCASEthat can never be matched because its lower value is greater than its upper value. So it's like, never gonna happen. π - A
LOGICAL SELECTconstruct has threeCASEstatements. Three? That's a crowd. π - A
TRANSFERspecifies a source that's shorter than the destination. That's not it, chief. π« - The type of a function result is declared more than once with the same type. If
-pedanticor standard-conforming mode is on, this is an error. So double-check that. π― - A
CHARACTERvariable is declared with negative length. Negative length? In this economy? π - 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.) Soomxis the sneaky one. π΅οΈββοΈ
-Wtabsβ by default, tabs are accepted as whitespace, but tabs aren't actually part of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported.-Wtabswill warn you if a tab is encountered. Note:-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018,-std=f2023and-Wall. So if you're team spaces, this is for you. π-Wundefined-do-loopβ warns if aDOloop with step either1or-1causes an underflow or overflow during iteration of the loop's induction variable. Implied by-Wall. So-Wallalready has your back. π«Ά-Wunderflowβ produces a warning when numerical constant expressions are encountered that yield an UNDERFLOW during compilation. Enabled by default. So it's always on, like your favorite playlist. πΆ-Wintrinsic-shadowβ warns if a user-defined procedure or module procedure has the same name as an intrinsic. In that case, you might need an explicit interface orEXTERNALorINTRINSICdeclaration to get calls resolved to the intrinsic/procedure you actually want. Implied by-Wall. So don't let your function get shadowed. β¨-Wuse-without-onlyβ warns if aUSEstatement has noONLYqualifier, so it implicitly imports all public entities of the used module. That's a lot of stuff. Maybe be more selective? πββοΈ-Wunused-dummy-argumentβ warns about unused dummy arguments. Implied by-Wall. So if you have a dummy that's just sitting there, it'll call it out. π-Wunused-parameterβ unlike gcc's meaning of-Wunused-parameter, gfortran's version doesn't warn about unused dummy arguments (that's-Wunused-dummy-argument), but about unusedPARAMETERvalues.-Wunused-parameteris implied by-Wextraif you also use-Wunusedor-Wall. So it's a team effort. π€-Walign-commonsβ by default, gfortran warns whenever variables are padded for proper alignment inside aCOMMONblock. You can turn this off with-Wno-align-commons. See also-falign-commons. So if you're all about that alignment, you've been warned. π-Wfunction-eliminationβ warns if any calls to impure functions are eliminated by optimizations enabled by-ffrontend-optimize. Implied by-Wextra. So if your function gets yeeted, you'll know. ποΈ-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 can reduce performance. If the array is already allocated with the correct shape, consider using a whole-array array-spec (like(:,:,:)) for the variable on the left-hand side to prevent the reallocation check. Note that sometimes the warning shows 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. So it's giving performance anxiety. π-Wrealloc-lhs-allβ warns when the compiler inserts code for allocation or reallocation of an allocatable variable; this includes scalars and derived types. So it's the extra version. π-Wcompare-realsβ warns when you compare real or complex types for equality or inequality. Implied by-Wextra. Because floating point comparison is a trap. πͺ€-Wtarget-lifetimeβ warns if the pointer in a pointer assignment might live longer than its target. Implied by-Wall. So it's like, "your pointer is gonna outlive its target, bestie." π-Wzerotripβ warns if aDOloop is known to execute zero times at compile time. Implied by-Wall. So if your loop is a no-op, you'll know. π«-Wdo-subscriptβ warns if an array subscript inside aDOloop could lead to an out-of-bounds access, even if the compiler can't prove the statement is actually executed. Like in this case:
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. So it's looking out for you. π
-Werrorβ turns all warnings into errors. So no more warnings, just errors. The ultimate vibe check. π₯
Some of these have no effect when compiling programs written in Fortran. So don't be surprised if some warnings are like, "I don't work here." π
π Options for debugging your program π
GNU Fortran has various special options for debugging your program. So if you're in detective mode, these are for you. π
-fdebug-aux-varsβ renames internal variables created by the gfortran front end and makes them accessible to a debugger. The names of these 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. So if you're deep in the compiler weeds, this is your new bestie. π«Ά-ffpe-trap=listβ okay so this one is your floating point exception trap situation π₯. You hand it a list, and on most systems, the moment a floating point exception goes down and the trap for that exception is on, aSIGFPEsignal gets sent, the program gets aborted, and you get a core file that is genuinely useful for debugging π.listis a (possibly empty) comma-separated list, eithernone(which clears the whole set of exceptions being trapped, bye π) or any of these bad boys:invalidβ invalid floating point operation, likeSQRT(-1.0), she's not okayzeroβ division by zero πoverflowβ 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 correspond to the five IEEE 754 exceptions, whereas the last one (denormal) is not part of the IEEE 754 standard, but it is available on some common architectures such as x86 β¨.
The first three exceptions (invalid, zero, and overflow) often indicate serious errors, and unless your program has provisions for dealing with these exceptions, enabling traps for these three is probably a good idea π.
If you use this option more than once on the command line, the lists get joined: -ffpe-trap=list1 -ffpe-trap=list2 is equivalent to -ffpe-trap=list1,list2 π
.
Bestie, listen: once an exception is enabled it cannot be disabled (there's no negative form), except by clearing all traps by specifying none. That's the only exit, no cap.
Many, if not most, floating point operations incur loss of precision due to rounding, and hence the -ffpe-trap=inexact is likely to be uninteresting in practice π₯±.
By default no exception traps are enabled.
-ffpe-summary=listβ this one specifies a list of floating-point exceptions whose flag status gets printed toERROR_UNITwhen you invokeSTOPandERROR STOPπ.listcan be eithernone,all, or a comma-separated list of:invalid,zero,overflow,underflow,inexactanddenormal. (See-ffpe-trapfor a description of the exceptions, it's all up there βοΈ.)
If the option is used more than once on the command line, only the last one will be used. No merging, it's not that kind of party π .
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 actioncore), 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, so keep that in mind, iykyk.
β¨ 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. Yes, sometimes they wander off π¦.
π 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, so don't come for them when they do nothing π.
-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. Rude, but that's how it is π.-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 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. This is the real-ones-only part of the page, bestie, read it twice π’.
π 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 suppport -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. Glow-up era, respectfully π«Ά.-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 itself. These are the backstage passes ποΈ.
-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. She's a little unstable, it's fine.-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-original instead. It's giving legacy, move on bestie π.
-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. Genius, honestly π.
-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. Sneaky little thing π.
-ff2cβ generate code designed to be compatible with code generated by g77 and f2c.
...okay continuing the -ff2c tea because bestie it is not done π
The calling conventions that g77 uses (originally implemented in f2c) are lowkey specific: they require functions that return type default REAL to actually return the C type double, and functions that return type COMPLEX to hand back their values via an extra argument in the calling sequence that points to where the return value should be stored. Under the default GNU calling conventions, those functions just return their results the way they would in GNU C β default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. Also, this option implies the -fsecond-underscore option, unless -fno-second-underscore is explicitly requested.
This does not affect the generation of code that interfaces with the libgfortran library.
Caution: it is not a good idea to mix Fortran code compiled with-ff2ctogether with code compiled using the default-fno-f2ccalling conventions, because callingCOMPLEXor defaultREALfunctions between program parts that were compiled with different calling conventions will break at execution time. π no cap.
Caution: this will break code which passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, since the library implementations use the-fno-f2ccalling conventions.
-fno-underscoringβ do not transform names of entities specified in the Fortran source file by appending underscores to them.
With -funderscoring in effect, GNU Fortran appends one underscore to external names. This is done to ensure compatibility with code produced by many UNIX Fortran compilers.
Caution: the default behavior of GNU Fortran is incompatible withf2candg77, so please use the-ff2coption if you want object files compiled with GNU Fortran to be compatible with object code created with these tools.
Use of -fno-underscoring is not recommended unless you are experimenting with issues such as integration of GNU Fortran into existing system environments (vis-Γ -vis existing libraries, tools, and so on).
For example, with -funderscoring, and assuming that j() and max_count() are external functions while my_var and lvar are local variables, a statement like
I = J() + MAX_COUNT (MY_VAR, LVAR)
is implemented as something akin to:
i = j_() + max_count_(&my_var, &lvar);
With -fno-underscoring, the same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
Use of -fno-underscoring allows direct specification of user-defined names while debugging and when interfacing GNU Fortran code with other languages.
Note that just because the names match does not mean that the interface implemented by GNU Fortran for an external name matches the interface implemented by some other language for that same name. That is, getting code produced by GNU Fortran to link to code produced by some other compiler using this or any other method can be only a small part of the overall solution β getting the code generated by both compilers to agree on issues other than naming can require significant effort, and, unlike naming disagreements, linkers normally cannot detect disagreements in these other areas.
Also, note that with -fno-underscoring, the lack of appended underscores introduces the very real possibility that a user-defined external name will conflict with a name in a system library, which could make finding unresolved-reference bugs quite difficult in some cases β they might occur at program run time, and show up only as buggy behavior at run time. π
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.
-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.
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>β coarray vibes, pick your keyword:noneβ disable coarray support; using coarray declarations and image-control statements will produce a compile-time error. (Default)singleβ single-image mode, i.e.num_images()is always one.libβ library-based coarray parallelization; a suitable GNU Fortran coarray library needs to be linked.
-fcheck=<keyword>β enable the generation of run-time checks; the argument shall be a comma-delimited list of the following keywords. Prefixing a check withno-disables it if it was activated by a previous specification.allβ enable all run-time test of-fcheck.array-tempsβ warns at run time when for passing an actual argument a temporary array had to be generated. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries.
Note: the warning is only printed once per location.
bitsβ enable generation of run-time checks for invalid arguments to the bit manipulation intrinsics.boundsβ enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds and ensures that all string lengths are equal for character array constructors without an explicit typespec.
Some checks require that -fcheck=bounds is set for the compilation of the main program.
Note: in the future this may also include other forms of checking, e.g., checking substring references.
doβ enable generation of run-time checks for invalid modification of loop iteration variables.memβ enable generation of run-time checks for memory allocation. Note: this option does not affect explicit allocations using theALLOCATEstatement, which will be always checked.pointerβ enable generation of run-time checks for pointers and allocatables.recursionβ enable generation of run-time checks for recursively called subroutines and functions which are not marked as recursive. See also-frecursive. Note: this check does not work for OpenMP programs and is disabled if used together with-frecursiveand-fopenmp.
Example: assuming you have a file foo.f90, the command
gfortran -fcheck=all,no-array-temps foo.f90
will compile the file with all checks enabled as specified above except warnings for generated array temporaries. β¨
-fbounds-checkβ deprecated alias for-fcheck=bounds.-ftail-call-workaround-ftail-call-workaround=nβ some C interfaces to Fortran codes violate the gfortran ABI by omitting the hidden character length arguments as described in β¦ This can lead to crashes because pushing arguments for tail calls can overflow the stack.
To provide a workaround for existing binary packages, this option disables tail call optimization for gfortran procedures with character arguments. With -ftail-call-workaround=2 tail call optimization is disabled in all gfortran procedures with character arguments, with -ftail-call-workaround=1 or equivalent -ftail-call-workaround only in gfortran procedures with character arguments that call implicitly prototyped procedures.
Using this option can lead to problems including crashes due to insufficient stack space. π
It is very strongly recommended to fix the code in question. The -fc-prototypes-external option can be used to generate prototypes which conform to gfortran's ABI, for inclusion in the source code.
Support for this option will likely be withdrawn in a future release of gfortran.
The negative form, -fno-tail-call-workaround or equivalent -ftail-call-workaround=0, can be used to disable this option.
Default is currently -ftail-call-workaround, this will change in future releases.
-fcheck-array-temporariesβ deprecated alias for-fcheck=array-temps.-fmax-array-constructor=nβ this option can be used to increase the upper limit permitted in array constructors. The code below requires this option to expand the array at compile time.
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
Caution: this option can lead to long compile times and excessively large object files.
The default value for n is 65535.
-fmax-stack-var-size=nβ this option specifies the size in bytes of the largest array that will be put on the stack; if the size is exceeded static memory is used (except in procedures marked asRECURSIVE). Use the option-frecursiveto allow for recursive procedures which do not have aRECURSIVEattribute or for parallel programs. Use-fno-automaticto never use the stack.
This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables. Future versions of GNU Fortran may improve this behavior.
The default value for n is 65536.
-fstack-arraysβ adding this option will make the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory. If your program uses very large local arrays it is possible that you will have to extend your runtime limits for stack memory on some operating systems. This flag is enabled by default at optimization level-Ofastunless-fmax-stack-var-sizeis specified. π¦-fpack-derivedβ tells GNU Fortran to pack derived type members as closely as physically possible, like sardines bestie π. Warning tho: code compiled with this is likely to be incompatible with code compiled without it, and it may also execute slower. So it's giving "trade-off" energy.-frepack-arraysβ sometimes GNU Fortran passes assumed shape array sections via a descriptor that describes a noncontiguous chunk of memory. This flag adds code to the function prologue so the data gets repacked into a contiguous block at runtime β¨. Result: faster accesses to the array. BUT β and this is the catch β it can introduce significant overhead to the function call, especially when the passed data is noncontiguous. So like, know your data babe.-fshort-enumsβ this one exists purely for interoperability with C code that was compiled with the-fshort-enumsoption π«Ά. It makes GNU Fortran pick the smallestINTEGERkind that a given enumerator set will fit in, and gives all its enumerators that kind.-finline-arg-packingβ okay so when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size procedure, or as an argument to a procedure that doesn't have an explicit interface, the argument may have to be packed β aka shoved 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 gets performed by inline code. That allows for more optimization while also increasing code size.
-finline-arg-packing is implied by any of the -O options except when optimizing for size via -Os. If your code contains a very large number of arguments that have to be packed, code size and compilation time may become excessive π. If that's the case, it may be better to disable this option. Instances of packing can be found by using -Warray-temporaries.
-fexternal-blasβ this makes gfortran generate calls to BLAS functions for some matrix operations likeMATMUL, instead of using our own algorithms, if the size of the matrices involved is larger than a given limit (see-fblas-matmul-limit). This may be profitable if an optimized vendor BLAS library is available π. The BLAS library 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 the others get handled by gfortran internal algorithms. If the matrices involved aren't square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices. The default value fornis30.-finline-matmul-limit=nβ when front-end optimization is active, some calls to theMATMULintrinsic function will be inlined. This may result in a code size increase if the size of the matrix can't be determined at compile time, since code for both cases is generated. Setting-finline-matmul-limit=0disables inlining in all cases. Setting this option with a value ofnwill produce inline code for matrices with size up ton. If the matrices involved aren't square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices. The default value fornis30. The-fblas-matmul-limitcan be used to change this value.-frecursiveβ allow indirect recursion by forcing all local arrays to be allocated on the stack π . Heads up: 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 isn't 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.
-falign-commonsβ by default, gfortran enforces 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 isn't 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's recommended to order objects from largest to smallest.-fno-protect-parensβ by default the parentheses in an expression 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's 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</c> to f. This option only works if -ffrontend-optimize is in effect.
-ffrontend-optimizeβ this option performs front-end optimization, based on manipulating parts 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. So yeah, no secret env vars to fiddle with here bestie, it's giving "nothing to see" π.
π BUGS π
For instructions on reporting bugs, see <http://bugzilla.redhat.com/bugzilla>.
π SEE ALSO π
gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1) and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb.
βοΈ AUTHOR βοΈ
See the Info entry for gfortran for contributors to GCC and GNU Fortran. Shoutout to the whole squad π«Ά.
Β©οΈ 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 the whole page, bestie!! πβ¨ This iconic lil manual is from gcc-14, dated 2026-07-24, and it lives in section 1 of the manual as GFORTRAN(1) π. Go forth and compile, you absolute legend ππ¦
π¦ where this page comes from
- fedora 43: gcc14-gfortran 14.4.1-2.fc43 Β· 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 curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms