GFORTRAN(1)
๐ GFORTRAN(1) ๐ โ the GNU Fortran compiler, bestie
okay so this is the manual page for gfortran, straight outta the GNU manual. it's a whole vibe, it's long, and we're doing it in 7 parts โ this is part 1, so don't go anywhere, there's more coming. ๐ฆ
๐ธ NAME ๐ธ
gfortran โ GNU Fortran compiler. that's it, that's the whole name section, she's concise. ๐
โจ 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 up here, bestie โ see below for the rest of them. there are so many more. like, so many.
๐ซถ DESCRIPTION ๐ซถ
the gfortran command supports all the options supported by the gcc command. but lowkey, only the options specific to GNU Fortran get documented here โ the gcc ones live in their own house.
all GCC and GNU Fortran options are accepted both by gfortran and by gcc (plus any other drivers built at the same time, like g++), because adding GNU Fortran to the GCC distribution means all the relevant drivers accept GNU Fortran options. slay, shared custody. ๐
in some cases, options have positive and negative forms โ the negative form of -ffoo would be -fno-foo. this manual only documents one of these two forms: whichever one is not the default. iykyk. ๐
๐ OPTIONS ๐
here's a summary of all the options specific to GNU Fortran, grouped by type. the explanations are in the following sections (and in the parts after this one, bestie).
๐ Fortran Language Options
-fall-intrinsics-fallow-argument-mismatch-fallow-invalid-boz-fbackslash-fcray-pointer-fd-lines-as-code-fd-lines-as-comments-fdec-fdec-char-conversions-fdec-structure-fdec-intrinsic-ints-fdec-static-fdec-math-fdec-include-fdec-format-defaults-fdec-blank-format-item-fdefault-double-8-fdefault-integer-8-fdefault-real-8-fdefault-real-10-fdefault-real-16-fdollar-ok-ffixed-line-length-n-ffixed-line-length-none-fpad-source-ffree-form-ffree-line-length-n-ffree-line-length-none-fimplicit-none-finteger-4-integer-8-fmax-identifier-length-fmodule-private-ffixed-form-fno-range-check-fopenacc-fopenmp-freal-4-real-10-freal-4-real-16-freal-4-real-8-freal-8-real-10-freal-8-real-16-freal-8-real-4-std=std-ftest-forall-temp
๐ Preprocessing Options
-A-question[=answer]-Aquestion=answer-C-CC-Dmacro[=defn]-H-P-Umacro-cpp-dD-dI-dM-dN-dU-fworking-directory-imultilib dir-iprefix file-iquote-isysroot dir-isystem dir-nocpp-nostdinc-undef
๐ Error and Warning Options
-Waliasing-Wall-Wampersand-Warray-bounds-Wc-binding-type-Wcharacter-truncation-Wconversion-Wdo-subscript-Wfunction-elimination-Wimplicit-interface-Wimplicit-procedure-Wintrinsic-shadow-Wuse-without-only-Wintrinsics-std-Wline-truncation-Wno-align-commons-Wno-overwrite-recursive-Wno-tabs-Wreal-q-constant-Wsurprising-Wunderflow-Wunused-parameter-Wrealloc-lhs-Wrealloc-lhs-all-Wfrontend-loop-interchange-Wtarget-lifetime-fmax-errors=n-fsyntax-only-pedantic-pedantic-errors
๐ Debugging Options
-fbacktrace-fdump-fortran-optimized-fdump-fortran-original-fdebug-aux-vars-fdump-fortran-global-fdump-parse-tree-ffpe-trap=list-ffpe-summary=list
๐ Directory Options
-Idir-Jdir-fintrinsic-modules-path dir
๐ Link Options
-static-libgfortran
๐ Runtime Options
-fconvert=conversion-fmax-subrecord-length=length-frecord-marker=length-fsign-zero
๐ Interoperability Options
-fc-prototypes-fc-prototypes-external
๐ Code Generation Options
-faggressive-function-elimination-fblas-matmul-limit=n-fbounds-check-ftail-call-workaround-ftail-call-workaround=n-fcheck-array-temporaries-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>-fcoarray=<none|single|lib>-fexternal-blas-ff2c-ffrontend-loop-interchange-ffrontend-optimize-finit-character=n-finit-integer=n-finit-local-zero-finit-derived-finit-logical=<true|false>-finit-real=<zero|inf|-inf|nan|snan>-finline-matmul-limit=n-finline-arg-packing-fmax-array-constructor=n-fmax-stack-var-size=n-fno-align-commons-fno-automatic-fno-protect-parens-fno-underscoring-fsecond-underscore-fpack-derived-frealloc-lhs-frecursive-frepack-arrays-fshort-enums-fstack-arrays
๐ง Options controlling Fortran dialect ๐ง
so the following options control the details of the Fortran dialect that the compiler will accept, periodt:
-ffree-form-ffixed-form
these two 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 filename is doing the talking. ๐
-fall-intrinsicsโ this option causes all intrinsic procedures (including the GNU-specific extensions) to be accepted. it can be useful with-std=to force standard-compliance but still get access to the full range of intrinsics available withgfortran. as a consequence,-Wintrinsics-stdwill be ignored and no user-defined procedure with the same name as any intrinsic will be called, except when it is explicitly declaredEXTERNAL. she's taking over. ๐-fallow-argument-mismatchโ some code contains calls to external procedures with mismatches between the calls and the procedure definition, or with mismatches between different calls. such code is non-conforming, and will usually be flagged with an error. this option degrades the error to a warning, which can only be disabled by disabling all warnings via-w. only a single occurrence per argument is flagged by this warning.-fallow-argument-mismatchis implied by-std=legacy.
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(*). bestie. please. ๐ญ
-fallow-invalid-bozโ a BOZ literal constant can occur in a limited number of contexts in standard conforming Fortran. this option degrades an error condition to a warning, and allows a BOZ literal constant to appear where the Fortran standard would otherwise prohibit its use.-fd-lines-as-code-fd-lines-as-comments
enable special treatment for lines beginning with "d" or "D" in fixed form sources. if the -fd-lines-as-code option is given, they are treated as if the first column contained a blank. if the -fd-lines-as-comments option is given, they are treated as comment lines. pick 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. look at her, doing extra work. ๐
-fdec-char-conversionsโ enable the use of character literals in assignments and"DATA"statements for non-character variables.-fdec-structureโ enable DEC"STRUCTURE"and"RECORD"as well as"UNION","MAP", and dot (.) as a member separator (in addition to%). this is provided for compatibility only โ Fortran 90 derived types should be used instead where possible.-fdec-intrinsic-intsโ enable B/I/J/K kind variants of existing integer functions (e.g. BIAND, IIAND, JIAND, etc...). for a complete list of intrinsics see the full documentation.-fdec-mathโ enable legacy math intrinsics such as COTAN and degree-valued trigonometric functions (e.g. TAND, ATAND, etc...) for compatability with older code.-fdec-staticโ enable DEC-style STATIC and AUTOMATIC attributes to explicitly specify the storage of variables and other objects.-fdec-includeโ enable parsing of INCLUDE as a statement in addition to parsing it as INCLUDE line. when parsed as INCLUDE statement, INCLUDE does not have to be on a single line and can use line continuations. she's flexible like that. ๐ฆ-fdec-format-defaultsโ enable format specifiers F, G and I to be used without width specifiers โ default widths will be used instead.-fdec-blank-format-itemโ enable a blank format item at the end of a format specification, i.e. nothing following the final comma. yes, the empty space is the point. ๐-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. not the$at the front, bestie, absolutely not. ๐-fbackslashโ change the interpretation of backslashes in string literals from a single backslash character to "C-style" escape characters. the following combinations are expanded"\a","\b","\f","\n","\r","\t","\v","\\", and"\0"to the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. additionally,"\x"nn,"\u"nnnnand"\U"nnnnnnnn(where each n is a hexadecimal digit) are translated into the Unicode characters corresponding to the specified code points. all other combinations of a character preceded by\are unexpanded.-fmodule-privateโ set the default accessibility of module entities to"PRIVATE". use-associated entities will not be accessible unless they are explicitly declared as"PUBLIC". gatekeeping, but make it Fortran. ๐ช-ffixed-line-length-nโ set the column after which characters are ignored in typical fixed-form lines in the source file, and, unless"-fno-pad-source", through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines.
popular values for n include 72 (the standard and the default), 80 (card image), and 132 (corresponding to "extended-source" options in some popular compilers). n may also be none, meaning that the entire line is meaningful and that continued character constants never have implicit spaces appended to them to fill out the line. -ffixed-line-length-0 means the same thing as -ffixed-line-length-none. iconic numbers honestly. โญ
-fno-pad-sourceโ by default fixed-form lines have spaces assumed (as if padded to that length) after the ends of short fixed-form lines. this is not done either if-ffixed-line-length-0,-ffixed-line-length-noneor if-fno-pad-sourceoption is used. with any of those options, continued character constants never have implicit spaces appended to them to fill out the line. no filler, no crumbs. ๐
okay bestie that's part 1 done โ parts 2 through 7 are still coming, so hold onto your ๐
-ffree-line-length-nโ bestie, this sets the column after which everything gets yeeted into the void on typical free-form source lines. Default is132. Andncan benone, meaning the whole line counts, every last character of it. Oh and-ffree-line-length-0is literally the same thing as-ffree-line-length-none. twins. ๐-fmax-identifier-length=nโ caps how long your identifiers are allowed to be. the classic values are31(Fortran 95) and63(Fortran 2003 and later). pick your era ๐-fimplicit-noneโ no implicit typing allowed, periodt. unless an explicitIMPLICITstatement overrides it. it's giving "addingimplicit noneto the start of every procedure" โจ-fcray-pointerโ turns on the Cray pointer extension, which hands you C-like pointer functionality. vintage but iconic ๐-fopenaccโ enables the OpenACC extensions. that means OpenACC!$accdirectives in free form andc$acc,*$accand!$accdirectives in fixed form,!$conditional compilation sentinels in free form andc$,*$and!$sentinels in fixed form. and when you're linking, it arranges for the OpenACC runtime library to get linked in too. slay ๐ฅ-fopenmpโ enables the OpenMP extensions: OpenMP!$ompdirectives in free form plusc$omp,*$ompand!$ompdirectives in fixed form,!$conditional compilation sentinels in free form plusc$,*$and!$sentinels in fixed form, and when linking it arranges for the OpenMP runtime library to be linked in. also important:-fopenmpimplies-frecursive. ๐-fno-range-checkโ turns OFF range checking on the results of simplification of constant expressions during compilation. so like, GNU Fortran would normally error at compile time when simplifyinga = 1. / 0. with this option? no error, andagets assigned the value+Infinity. if an expression evaluates to something outside the relevant range of[-HUGE():HUGE()], the expression gets replaced by-Infor+Infas appropriate. same energy forDATA i/Z'FFFFFFFF'/โ normally that's an integer overflow on most systems, but with-fno-range-checkthe value will "wrap around" andigets initialized to-1instead. ๐ญ-fdefault-integer-8โ sets the default integer and logical types to an 8 byte wide type. this 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. also affects the kind of non-double real constants like1.0. it promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. but if-fdefault-double-8is given along withfdefault-real-8, thenDOUBLE PRECISIONand double real constants are not promoted. and unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations. ๐-fdefault-real-10โ sets the default real type to an 10 byte wide type. also affects the kind of non-double real constants like1.0. promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. if-fdefault-double-8is given along with-fdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. 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. also affects the kind of non-double real constants like1.0. promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. if-fdefault-double-8is given along with-fdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations. ๐ฆ-fdefault-double-8โ sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8 byte wide type. does nothing if that's already the default. this one is the vibe blocker: it prevents-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes. ๐-finteger-4-integer-8โ promotes allINTEGER(KIND=4)entities toINTEGER(KIND=8)entities. ifKIND=8is unavailable, an error gets issued.
okay listen, use this one with care, it may not be suitable for your codes fr fr. areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. inspecting the intermediate representation of the translated Fortran code, produced by-fdump-tree-original, is suggested. ๐
-freal-4-real-8,-freal-4-real-10,-freal-4-real-16,-freal-8-real-4,-freal-8-real-10,-freal-8-real-16โ these promote allREAL(KIND=M)entities toREAL(KIND=N)entities. ifREAL(KIND=N)is unavailable, an error gets issued. the-freal-4-flags also affect the default real kind, and the-freal-8-flags also affect the double-precision real kind. all other real-kind types are unaffected by this option. the promotion is also applied to real literal constants of default and double-precision kind and a specified kind number 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. also note that forREAL(KIND=KIND(1.0))the literal may get promoted and then the result may get promoted again. ๐
these options should be used with care and may not be suitable for your codes. areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O and calls to intrinsic procedures when passing a value to thekind=dummy argument. inspecting the intermediate representation of the translated Fortran code, produced by-fdump-fortran-originalor-fdump-tree-original, is suggested. ๐
-std=stdโ tells the compiler which standard your program is expected to conform to, andstdcan be one off95,f2003,f2008,f2018,gnu, orlegacy. the default forstdisgnu, which specifies a superset of the latest Fortran standard that includes all the extensions GNU Fortran supports โ though warnings will be given for obsolete extensions that aren't recommended for use in new code. thelegacyvalue is equivalent but without those warnings for obsolete extensions, and it may be useful for old non-standard programs.f95,f2003,f2008, andf2018specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards. also, the deprecated option-std=f2008tsacts as an alias for-std=f2018โ it's only present for backwards compatibility with earlier gfortran versions and should not be used any more. don't do it bestie, it's old news ๐ธ-ftest-forall-tempโ enhances test coverage by forcing mostforallassignments to use a temporary. nerdy and we love her for it โญ
โจ Enable and customize preprocessing โจ
so many Fortran compilers โ GNU Fortran included โ let you shove your source code through a C preprocessor (CPP, sometimes also called the Fortran preprocessor, FPP) so you can do conditional compilation. in GNU Fortran's case, that's the GNU C Preprocessor in traditional mode. ๐
on systems with case-preserving file names, the preprocessor gets invoked automatically when the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. wanna manually invoke it on any file? use -cpp. wanna disable preprocessing on files where it runs automatically? use -nocpp. easy. ๐
if a preprocessed file includes another file with the Fortran INCLUDE statement, the included file is not preprocessed. to preprocess included files, use the equivalent preprocessor statement #include. no cap. ๐ฆ
if GNU Fortran invokes the preprocessor, __GFORTRAN__ is defined. the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ can be used to determine the version of the compiler. see Top,,Overview,cpp,The C Preprocessor for details. ๐
GNU Fortran supports a number of INTEGER and REAL kind types in addition to the kind types the Fortran standard requires. whether any given kind type is available depends on your architecture, bestie. the following pre-defined preprocessor macros can be used to conditionally include code for these additional kind types: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__. ๐
and now for the lore: while CPP is the de-facto standard for preprocessing Fortran code, Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional Compilation, which is not widely used and not directly supported by the GNU Fortran compiler. you can use the program coco to preprocess such files (http://www.daniellnagle.com/coco.html). ๐
the following options control preprocessing of Fortran code:
-cpp,-nocppโ enable preprocessing. the preprocessor is automatically invoked if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08. use this option to manually enable preprocessing of any kind of Fortran file.
to disable preprocessing of files with any of the above listed extensions, use the negative form: -nocpp.
the preprocessor is run in traditional mode. any restrictions of the file-format, especially the limits on line length, apply for preprocessed output as well, so it might be advisable to use the -ffree-line-length-none or -ffixed-line-length-none options. ๐
-dMโ instead of the normal output, generate a list of#definedirectives for all the macros defined during the execution of the preprocessor, including predefined macros. this gives you a way of finding out what is predefined in your version of the preprocessor. assuming you have no filefoo.f90, the command
touch foo.f90; gfortran -cpp -E -dM foo.f90
will show all the predefined macros. โญ
-dDโ bestie this one is-dM's slightly different cousin, and it differs in exactly two ways: 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โ literally just like-dD, but it emits only the macro names, not their expansions. Name-only, no receipts. ๐-dUโ like-dDexcept 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. iykyk ๐ฆ-dIโ outputs'#include'directives in addition to the result of preprocessing. ๐-fworking-directoryโ enables 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 -P flag 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 -C option, the -CC option causes all C++-style comments inside a macro to be converted to C-style comments. This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line. The -CC option is generally used to support lint comments.
โ ๏ธ Warning: this currently handles C- and C++-Style comments only. The preprocessor does not yet recognize Fortran-style comments. ๐
-Dnameโ predefine name as a macro, with definition1. โญ-Dname=definitionโ the contents of definition are tokenized and processed as if they appeared during translation phase three in a'#define'directive. In particular, the definition will be truncated by embedded newline characters.
If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax. ๐
If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you will need to quote the option. With sh and csh, "-D'name(args...)=definition'" works. ๐
-D and -U options are processed in the order they are given on the command line. All -imacros file and -include file options are processed after all -D and -U options. ๐
-Hโ print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the'#include'stack it is. ๐-Pโ inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers. ๐ฆ-Unameโ cancel any previous definition of name, either built in or provided with a-Doption. ๐
โจ Options to request or suppress errors and warnings โจ
Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler will continue to process the program in an attempt to report further errors to aid in debugging, but will not produce any compiled output. ๐ญ
Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there is likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. ๐
You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default. iykyk โจ
These options control the amount and kinds of errors and warnings produced by GNU Fortran:
-fmax-errors=n โ limits the maximum number of error messages to n, at which point GNU Fortran bails out rather than attempting to continue processing the source code. If n is0, there is no limit on the number of error messages produced. ๐-fsyntax-onlyโ check the code for syntax errors, but do not actually compile it. This will generate module files for each module present in the code, but no other output file. ๐-Wpedantic-pedanticโ issue warnings for uses of extensions to Fortran.-pedanticalso applies to C-language constructs where they occur in GNU Fortran source files, such as use of\ein a character constant within a directive like"#include".
Valid Fortran programs should compile properly with or without this option. However, without this option, certain GNU extensions and traditional Fortran features are supported as well. With this option, many of them are rejected.
Some users try to use -pedantic to check programs for conformance. They soon find that it does not do quite what they want---it finds some nonstandard practices, but not all. However, improvements to GNU Fortran in this area are welcome. ๐ซถ
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018. โจ
-pedantic-errorsโ like-pedantic, except that errors are produced rather than warnings. ๐ญ-Wallโ enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. This currently includes-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop. ๐-Waliasingโ warn about possible aliasing of dummy arguments. Specifically, it warns if the same actual argument is associated with a dummy argument with"INTENT(IN)"and a dummy argument with"INTENT(OUT)"in a call with an explicit interface. ๐
The following example will trigger the warning:
interface
subroutine bar(a,b)
integer, intent(in) :: a
integer, intent(out) :: b
end subroutine
end interface
integer :: a
call bar(a,a)
-Wampersandโ warn about missing ampersand in continued character constants. The warning is given with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008and-std=f2018.
๐ Note: With no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that initiated the continuation. ๐ฆ
-Warray-temporariesโ warn about array temporaries generated by the compiler. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries. โญ-Wc-binding-typeโ warns you if a variable might not be C interoperable ๐ like bestie... if you declared it with an intrinsic type using the default kind instead of a kind parameter that's actually defined for C interop in theISO_C_Bindingmodule? Yeah. That. Implied by-Wall.-Wcharacter-truncationโ yells at you when a character assignment is gonna truncate the string you're assigning. The string does NOT fit, and it's gonna tell you ๐ญ-Wline-truncationโ warns when a source code line is gonna get truncated. Implied by-Wall. And for free-form source code, the default is-Werror=line-truncation, so truncations get reported as an error, not a lil warning. periodt.-Wconversionโ warns about implicit conversions that are likely to change the value of the expression after conversion ๐ Implied by-Wall.-Wconversion-extraโ warns about implicit conversions between different types and kinds. Heads up: this one does not imply-Wconversion.-Wextraโ turns on a bunch of warning options for language features that might be problematic. Currently that includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscriptโจ-Wfrontend-loop-interchangeโ warns when you're using-ffrontend-loop-interchangeto do loop interchanges.-Wimplicit-interfaceโ warns if a procedure gets called without an explicit interface. ngl, note that this only checks that an explicit interface is present โ it does not check that the declared interfaces are consistent across program units. So like... it's checking the vibe, not the receipts.-Wimplicit-procedureโ warns if a procedure is called that has neither an explicit interface nor has been declared asEXTERNAL.-Winteger-divisionโ warns if a constant integer division truncates its result. Example:3/5evaluates to0๐ math is mathing in a way you did not ask for.-Wintrinsics-stdโ warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (with-std) and treats it as anEXTERNALprocedure because of that. You can use-fall-intrinsicsto never trigger this behavior and always link to the intrinsic regardless of the selected standard ๐-Wno-overwrite-recursiveโ do not warn when-fno-automaticis used with-frecursive. Lowkey important: 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. Handy for build environments that use-Werror.-Wreal-q-constantโ produces a warning if a real-literal-constant contains aqexponent-letter.-Wsurprisingโ produces a warning when "suspicious" code constructs show up. Technically legal, but they usually mean somebody made a mistake ๐
This currently produces a warning under the following circumstances:
- An
INTEGER SELECTconstruct has aCASEthat can never be matched because its lower value is greater than its upper value. - A
LOGICAL SELECTconstruct has threeCASEstatements. - A
TRANSFERspecifies a source that is shorter than the destination. - The type of a function result is declared more than once with the same type. If
-pedanticor standard-conforming mode is enabled, this is an error. - A
CHARACTERvariable is declared with negative length.
-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.-Wtabswill cause a warning to be issued if a tab is encountered. Note:-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall.-Wundefined-do-loopโ warns if aDOloop with step either1or-1yields an underflow or an overflow during iteration of an induction variable of the loop. Implied by-Wall.-Wunderflowโ produces a warning when numerical constant expressions are encountered that yield an UNDERFLOW during compilation. Enabled by default โจ-Wintrinsic-shadowโ warns if a user-defined procedure or module procedure has the same name as an intrinsic. In this case, an explicit interface orEXTERNALorINTRINSICdeclaration might be needed to get calls later resolved to the desired intrinsic/procedure. Implied by-Wall.-Wuse-without-onlyโ warns if aUSEstatement has noONLYqualifier and thus implicitly imports all public entities of the used module. The way that it just drags everything in... ๐ซ-Wunused-dummy-argumentโ warns about unused dummy arguments. Implied by-Wall.-Wunused-parameterโ okay so contrary to gcc's meaning of-Wunused-parameter, gfortran's implementation of this option does not warn about unused dummy arguments (that's-Wunused-dummy-argument's whole thing), but about unusedPARAMETERvalues.-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 aCOMMONblock. You can turn this warning off via-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationโ warns if any calls to impure functions are eliminated by the optimizations enabled by the-ffrontend-optimizeoption. Implied by-Wextra.-Wrealloc-lhsโ warns when the compiler might insert code for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature may reduce performance ๐ฌ If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g.(:,:,:)) for the variable on the left-hand side to prevent the reallocation check. Note that in some cases the warning is shown even if the compiler will optimize reallocation checks away โ for instance, when the right-hand side contains the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allโ warns when the compiler inserts code for allocation or reallocation of an allocatable variable; this includes scalars and derived types.-Wcompare-realsโ warns when comparing real or complex types for equality or inequality. Implied by-Wextra. (fr fr don't compare floats like that bestie)-Wtarget-lifetimeโ warns if the pointer in a pointer assignment might be longer than its target. Implied by-Wall.-Wzerotripโ warns if aDOloop is known to execute zero times at compile time. Implied by-Wall.-Wdo-subscriptโ warns if an array subscript inside aDOloop could lead to an out-of-bounds access, even if the compiler can't prove that the statement is actually executed. In cases like:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
Implied by -Wextra.
-Werrorโ turns all warnings into errors ๐ no more "lol whatever", everything is now a crisis.
Some of these have no effect when compiling programs written in Fortran.
๐ Options for debugging your program or GNU Fortran ๐
GNU Fortran has various special options used for debugging either your program or the GNU Fortran compiler itself. Very "look inside the machine" of it all ๐ง
-fdump-fortran-originalโ outputs the internal parse tree after translating the source program into internal representation. This option is mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added ๐-fdump-fortran-optimizedโ outputs the parse tree after front-end optimization. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added.-fdump-parse-treeโ outputs the internal parse tree after translating the source program into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added. โ ๏ธ This option is deprecated; use-fdump-fortran-originalinstead.-fdebug-aux-varsโ renames internal variables created by the gfortran front end and makes them accessible to a debugger. The name of the internal variables then starts 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.-fdump-fortran-globalโ outputs a list of the global identifiers after translating into middle-end representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added.-ffpe-trap=listโ specify a list of floating point exception traps to enable. On most systems, if a floating point exception occurs and the trap for that exception is enabled, aSIGFPEsignal will be sent and the program aborted, producing a core file useful for debugging ๐
list is a (possibly empty) comma-separated list of the following exceptions: invalid (invalid floating point operation, such as SQRT(-1.0)), zero (division by zero), overflow (overflow in a floating point operation), underflow (underflow in a floating point operation), inexact (loss of precision during operation), and denormal (operation performed on a denormal value). The first five exceptions correspond to the five IEEE 754 exceptions, whereas the last one (denormal) is not part of the IEEE 754 standard but is available on some common architectures such as x86.
The first three exceptions (invalid, zero, and overflow) often indicate serious errors, and unless the program has provisions for dealing with these exceptions, enabling traps for these three exceptions is probably a good idea ๐
If the option is used more than once in the command line, the lists will be joined: "ffpe-trap="list1 "ffpe-trap="list2 is equivalent to "ffpe-trap="list1,list2.
Okay so real talk bestie: once you flip an exception trap on, it stays on. There is literally no negative form, no undo, no take-backs, no "jk lol". ๐
And also? Like, most floating point operations โ genuinely most of them โ lose precision from rounding, which means ffpe-trap=inexact is gonna be highkey uninteresting in practice. It'll just vibe there firing off constantly. ๐
By default, no exception traps are enabled. Zero. None. Nada. โจ
-ffpe-summary=listโ tells the compiler which floating-point exceptions should have their flag status printed toERROR_UNITwhen you invokeSTOPandERROR STOP. The list can benone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (Peep-ffpe-trapfor a description of what each exception actually is, iykyk.)
If you use this option more than once on the command line, only the last one counts. Periodt.
By default, a summary for all exceptions but inexact is shown. ๐
-fno-backtraceโ so when a serious runtime error happens, or a deadly signal gets emitted (we're talking 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. Heads up though: this option only has influence for compilation of the Fortran main program. ๐ซถ
๐ฆ Options for directory search ๐ฆ
These options affect how GNU Fortran searches for files specified by the INCLUDE directive, and where it searches for previously compiled modules.
It also affects the search paths used by cpp when used to preprocess Fortran source. โจ
-Idirโ these affect interpretation of theINCLUDEdirective (as well as of the#includedirective of the cpp preprocessor).
Also note that the general behavior of -I and INCLUDE is pretty much the same as of -I with #include in the cpp preprocessor, with regard to looking for header.gcc files and other such things.
This path is also used to search for .mod files when previously compiled modules are required by a USE statement. ๐
-Jdirโ this option specifies where to put.modfiles for compiled modules. It is also added to the list of directories to searched by anUSEstatement.
The default is the current directory. ๐
-fintrinsic-modules-path dirโ this option specifies the location of pre-compiled intrinsic modules, if they are not in the default location expected by the compiler. ๐ธ
๐ Influencing the linking step ๐
These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler is not doing a link step. (Sorry bestie, no link step = no vibes.)
-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. ๐
๐ Influencing runtime behavior ๐
These options affect the runtime behavior of programs compiled with GNU Fortran. Main character energy for your binaries, fr fr.
-fconvert=conversionโ specify the representation of data for unformatted files. Valid values for conversion 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. ๐
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. โ
๐ 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. It's giving โจpuzzleโจ but it's actually easy, bestie.
-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. (Silently! Rude but okay. ๐)
-ff2cโ generate code designed to be compatible with code generated by g77 and f2c. ๐ฐ๏ธ
The calling conventions used by g77 (originally implemented in f2c) require functions that return type default REAL to actually return the C type double, and functions that return type COMPLEX to return the values via an extra argument in the calling sequence that points to where to store the return value. Under the default GNU calling conventions, such functions simply return their results as they would in GNU C โ default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. Additionally, this option implies the -fsecond-underscore option, unless -fno-second-underscore is explicitly requested.
This does not affect the generation of code that interfaces with the libgfortran library.
Caution: It is not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions as, callingCOMPLEXor defaultREALfunctions between program parts which were compiled with different calling conventions will break at execution time. ๐ Like, break break.
Caution: This will break code which passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, as the library implementations use the-fno-f2ccalling conventions. ๐ญ
-fno-underscoringโ do not transform names of entities specified in the Fortran source file by appending underscores to them.
With -funderscoring in effect, GNU Fortran appends one underscore to external names with no underscores. This is done to ensure compatibility with code produced by many UNIX Fortran compilers.
Caution: The default behavior of GNU Fortran is incompatible with f2c and g77, please use the -ff2c option 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-a-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>โ okay so this one takes a keyword, and here's the tea on the first one:noneโ disable coarray support; using coarray declarations and image-control statements will produce a compile-time error. (Default) ๐ซ
singleโ single-image mode, meaningnum_images()is always one. periodt. ๐libโ library-based coarray parallelization; you gotta link a suitable GNU Fortran coarray library for this to work. ๐ซถ-fcheck=<keyword>โ turns on the generation of run-time checks. The argument has to be a comma-delimited list of the keywords below. And bestie, here's the trick: slap ano-in front of a check and it turns that check off if some earlier specification had turned it on. โจallโ enable all the run-time tests of-fcheck. go big or go home. ๐ฅarray-tempsโ warns you at run time when a temporary array had to be generated in order to pass an actual argument. that info is sometimes lowkey useful for optimization, since it lets you dodge those temporaries. ngl, worth knowing.
Note: the warning is only printed once per location. once and done, she said it, she meant it. ๐
bitsโ enables run-time checks for invalid arguments handed to the bit manipulation intrinsics.boundsโ enables 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 makes sure all string lengths are equal for character array constructors without an explicit typespec. queen of thoroughness ๐
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. future era stuff, iykyk.
doโ enables run-time checks for invalid modification of loop iteration variables. don't touch the loop counter, babe ๐ญmemโ enables run-time checks for memory allocation.
Note: this option does not affect explicit allocations using the ALLOCATE statement, which will be always checked. that one's on lock already ๐
pointerโ enables run-time checks for pointers and allocatables.recursionโ enables 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: say you've got a file foo.f90. then this command
gfortran -fcheck=all,no-array-temps foo.f90
will compile that file with all checks enabled as specified above โ except warnings for generated array temporaries. the no- ate, as it should ๐
-fbounds-checkโ deprecated alias for-fcheck=bounds. it's giving legacy, bestie, please use the new one ๐ฅฒ-ftail-call-workaround-ftail-call-workaround=nโ so some C interfaces to Fortran codes violate the gfortran ABI by omitting the hidden character length arguments as described in . and that can lead to crashes, because pushing arguments for tail calls can overflow the stack. ๐ญ
To provide a workaround for existing binary packages, this option disables tail call optimization for gfortran procedures with character arguments. With -ftail-call-workaround=2 tail call optimization is disabled in all gfortran procedures with character arguments; with -ftail-call-workaround=1 โ or the equivalent plain -ftail-call-workaround โ it's disabled 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. so, like, don't get attached โจ
The negative form, -fno-tail-call-workaround or equivalent -ftail-call-workaround=0, can be used to disable this option.
Default is currently -ftail-call-workaround, this will change in future releases. heads up, the vibes are shifting ๐
-fcheck-array-temporariesโ deprecated alias for-fcheck=array-temps. another one for the archive ๐ผ-fmax-array-constructor=nโ this one lets you raise the upper limit permitted in array constructors. the code below needs this option in order 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. it's giving "why is my build still going" ๐
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 that size is exceeded, static memory is used instead (except in procedures marked asRECURSIVE). use the option-frecursiveto allow for recursive procedures which don't have aRECURSIVEattribute, or for parallel programs. use-fno-automaticto never use the stack. ๐ซถ
Right now this option only affects local arrays declared with constant bounds, and it may not apply to all character variables. future versions of GNU Fortran may improve this behavior. โจ
The default value for n is 65536.
-fstack-arraysโ adding this option makes the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory. if your program uses very large local arrays, it's possible you'll have to extend your runtime limits for stack memory on some operating systems. this flag is enabled by default at optimization level-Ofastunless-fmax-stack-var-sizeis specified. stack era ๐-fpack-derivedโ tells GNU Fortran to pack derived type members as closely as possible. code compiled with this option is likely to be incompatible with code compiled without it, and may execute slower. it's giving "cute but risky" ๐-frepack-arraysโ in some circumstances GNU Fortran may pass assumed shape array sections via a descriptor describing a noncontiguous area of memory. this option adds code to the function prologue to repack the data into a contiguous block at runtime.
This should result in faster accesses to the array. However, it can introduce significant overhead to the function call, especially when the passed data is noncontiguous. trade-offs, always trade-offs ๐ฆ
-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 will fit in, and give all its enumerators that kind. tiny but mighty ๐-finline-arg-packingโ when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size one, or as an argument to a procedure that doesn't have an explicit interface, the argument may have to be packed โ that is, put into contiguous memory. an example is the call tofooin
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
When -finline-arg-packing is in effect, this packing will be performed by inline code. This allows for more optimization while increasing code size.
-finline-arg-packing is implied by any of the -O options except when optimizing for size via -Os. If the code contains a very large number of argument that have to be packed, code size and also compilation time may become excessive. If that is the case, it may be better to disable this option. Instances of packing can be found by using -Warray-temporaries. ๐
-fexternal-blasโ 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) n will be performed by calls to BLAS functions, while the others will be handled by gfortran internal algorithms. if the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices.
The default value for n is 30.
-finline-matmul-limit=nโ when front-end optimization is active, some calls to theMATMULintrinsic function will be inlined. this may result in code size increase if the size of the matrix can't be determined at compile time, since code for both cases gets generated. setting-finline-matmul-limit=0will disable inlining in all cases. setting this option with a value of n will produce inline code for matrices with size up to n. if the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices.
The default value for n is 30. The -fblas-matmul-limit can be used to change this value. ๐ฅ
-frecursiveโ allow indirect recursion by forcing all local arrays to be allocated on the stack. this flag cannot be used together with-fmax-stack-var-size=or-fno-automatic. pick a lane, bestie ๐ญ-finit-local-zero-finit-derived-finit-integer=n-finit-real=<zero|inf|-inf|nan|snan>-finit-logical=<true|false>-finit-character=nโ 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 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.
like, they just don't. it's giving boundaries ๐
โฆand yeah, these limitations may be removed in future releases, so don't @ me ๐ซ
Heads up tho, bestie: the -finit-real=nan option initializes REAL and COMPLEX variables with a quiet NaN. Wanna go feral with a signalling NaN? Use -finit-real=snan. But lowkey watch out โ compile-time optimizations may convert them into quiet NaN anyway, and trapping needs to be enabled for it to matter (e.g. via -ffpe-trap). It's giving "I set the trap but nobody came" ๐ญ
Also the -finit-integer option will parse the value into an integer of type INTEGER(kind=C_LONG) on the host. That 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. Math said no ๐
And finally, real talk: enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables. No snitching, no warnings. ๐
-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 โจ. But if aCOMMONblock is not declared with consistent data types everywhere, this padding can cause trouble, and-fno-align-commonscan be used to disable automatic alignment. The same form of this option should be used for all files that share aCOMMONblock. And to avoid potential alignment issues inCOMMONblocks, it is recommended to order objects from largest to smallest โ biggest to smallest, main character to supporting cast ๐-fno-protect-parensโ by default the parentheses in expression are honored for all optimization levels such that the compiler does not 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. So like, parens are sacred until you say-Ofast, then it's every expression for itself ๐-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. It just... reshapes itself. Iconic behavior, no cap.-faggressive-function-eliminationโ functions with identical argument lists are eliminated within statements, regardless of whether these functions are markedPUREor not ๐ณ. For example, in
a = f(b,c) + f(b,c)
there will only be a single call to f. One call. That's it. Efficiency ate and left no crumbs ๐ฝ๏ธ. This option only works if -ffrontend-optimize is in effect, so don't forget the prerequisite bestie.
-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. Turning it off is valid, just saying ๐
-ffrontend-loop-interchangeโ attempt to interchange loops in the Fortran front end where profitable ๐. Enabled by default by any-Ooption. At the moment, this option only affectsFORALLandDO CONCURRENTstatements with several forall triplets. It's niche, it's specific, and it's doing its little loop shuffle anyway ๐ง
๐ 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 no secret env vars to memorize here โ it just vibes with whatever gcc is doing ๐
๐ BUGS ๐
For instructions on reporting bugs, see file:///usr/share/doc/gcc-12/README.Bugs. Found a bug? Tell the devs, they wanna know, fr fr ๐ซถ
๐ SEE ALSO ๐
gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1) and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb.
The whole friend group, assembled ๐
โ๏ธ AUTHOR โ๏ธ
See the Info entry for gfortran for contributors to GCC and GNU Fortran. Shoutout to everyone who contributed, we love you ๐
๐ COPYRIGHT ๐
Copyright (c) 2004-2022 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.
That's the whole page bestie, you made it to the end and you ATE ๐ This one's from thegcc-12set, dated2022-03-19, and yes it'sGFORTRAN(1)โ go compile something beautiful ๐ โจ
๐ฆ where this page comes from
- ubuntu jammy: gfortran-12 12-20220319-1ubuntu1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms