GFORTRAN

Section: GNU (1)
Updated: 2004-10-19
 

NAME

gfortran - GNU Fortran 95 compiler  

SYNOPSIS

gfortran [-c|-S|-E]
         [-g] [-pg] [-Olevel]
         [-Wwarn...] [-pedantic]
         [-Idir...] [-Ldir...]
         [-Dmacro[=defn]...] [-Umacro]
         [-foption...]          [-mmachine-option...]

         [-o outfileinfile...

Only the most useful options are listed here; see below for the remainder.  

DESCRIPTION

The gfortran command supports all the options supported by the gcc command. Only options specific to gfortran are documented here.

All gcc and gfortran 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 gfortran to the gcc distribution enables acceptance of gfortran options by all of the relevant drivers.

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.  

OPTIONS

Here is a summary of all the options specific to GNU Fortran, grouped by type. Explanations are in the following sections.
Fortran Language Options
-ffree-form -fno-fixed-form -fdollar-ok -fimplicit-none -fmax-identifier-length -std=std -ffixed-line-length-n -ffixed-line-length-none -i8 -r8 -d8
Warning Options
-fsyntax-only -pedantic -pedantic-errors -w -Wall -Waliasing -Wconversion -Wimplicit-interface -Wsurprising -Wunderflow -Wunused-labels -Wline-truncation -Werror -W
Debugging Options
-fdump-parse-tree
Directory Options
-Idir -Mdir
Code Generation Options
-fno-underscoring -fno-second-underscore -fbounds-check -fmax-stack-var-size=n -fpackderived -frepack-arrays
 

Options Controlling Fortran Dialect

The following options control the dialect of Fortran that the compiler accepts:
-ffree-form
-ffixed-form
Specify the layout used by the the source file. The tree form layout was introduced in Fortran 90. Fixed form was traditionally used in older Fortran programs.
-fdollar-ok
Allow $ as a valid character in a symbol name.
-ffixed-line-length-n
Set column after which characters are ignored in typical fixed-form lines in the source file, and 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 (corresponds to ``extended-source'' options in some popular compilers). n may 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.

-fmax-identifier-length=n
Specify the maximum allowed identifier length. Typical values are 31 (Fortran 95) and 63 (Fortran 200x).
-fimplicit-none
Specify that no implicit typing is allowed, unless overridden by explicit IMPLICIT statements. This is the equivalent of adding implicit none to the start of every procedure.
-std=std
Conform to the specified standard. Allowed values for std are gnu, f95 and f90.
-i8
-r8
-d8
The -i8 and -r8 options set the default "INTEGER" and "REAL" kinds to "KIND=8". The -d8 option is equivalent to specifying both -i8 and -r8.

When -r8 is specified, the "DOUBLE PRECISION" kind is set to "KIND=16" if the target supports a 16 byte floating point format. If no such format exists, the "DOUBLE PRECISION" kind is unchanged.

 

Options to Request or Suppress Warnings

Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there might have been an error.

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 warnings produced by GNU Fortran:

-fsyntax-only
Check the code for syntax errors, but don't do anything beyond that.
-pedantic
Issue warnings for uses of extensions to FORTRAN 95. -pedantic also applies to C-language constructs where they occur in GNU Fortran source files, such as use of \e in a character constant within a directive like #include.

Valid FORTRAN 95 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 gfortran in this area are welcome.

This should be used in conjunction with -std=std.

-pedantic-errors
Like -pedantic, except that errors are produced rather than warnings.
-w
Inhibit all warning messages.
-Wall
Enables commonly used warning options that which pertain to usage that we recommend avoiding and that we believe is easy to avoid. This currently includes -Wunused-labels, -Waliasing, -Wsurprising and -Wline-truncation.
-Waliasing
Warn about possible aliasing of dummy arguments. The following example will trigger the warning as it would be illegal to "bar" to modify either parameter.

          INTEGER A
          CALL BAR(A,A)

-Wconversion
Warn about implicit conversions between different types.
-Wimplicit-interface
Warn about when procedure are called without an explicit interface. Note this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units.
-Wsurprising
Produce a warning when ``suspicious'' code constructs are encountered. While technically legal these usually indicate that an error has been made.

This currently produces a warning under the following circumstances:

*
An INTEGER SELECT construct has a CASE the can never be matched as it's lower value that is greater than its upper value.
*
A LOGICAL SELECT construct has three CASE statements.
-Wunderflow
Produce a warning when numerical constant expressions are encountered, which yield an UNDERFLOW during compilation.
-Wunused-labels
Warn whenever a label is defined but never referenced.
-Werror
Turns all warnings into errors.
-W
Turns on ``extra warnings'' and, if optimization is specified via -O, the -Wuninitialized option. (This might change in future versions of gfortran

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 that are used for debugging either your program or gfortran
-fdump-parse-tree
Output the internal parse tree before starting code generation. Only really useful for debugging gfortran itself.
 

Options for Directory Search

There options affect how affect how gfortran searches for files specified via 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 the "INCLUDE" directive (as well as of the "#include" directive 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.

-Mdir
-Jdir
This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to searched by an "USE" statement.

The default is the current directory.

-J is an alias for -M to avoid conflicts with existing GCC options.

 

Options for Code Generation Conventions

These machine-independent options control the interface conventions used in code generation.

Most of them have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed---the one which is not the default. You can figure out the other form by either removing no- or adding it.

-fno-underscoring
Do not transform names of entities specified in the Fortran source file by appending underscores to them.

With -funderscoring in effect, gfortran appends two underscores to names with underscores and one underscore to external names with no underscores. (gfortran also appends two underscores to internal names with underscores to avoid naming collisions with external names. The -fno-second-underscore option disables appending of the second underscore in all cases.)

This is done to ensure compatibility with code produced by many UNIX Fortran compilers, including f2c which perform the same transformations.

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 other defaults like -fcase-lower and 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 gfortran code with other languages.

Note that just because the names match does not mean that the interface implemented by gfortran for an external name matches the interface implemented by some other language for that same name. That is, getting code produced by gfortran 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 gfortran 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.

-fno-second-underscore
Do not append a second underscore to names of entities specified in the Fortran source file.

This option has no effect if -fno-underscoring is in effect.

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__.

-fbounds-check
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.

In the future this may also include other forms of checking, eg. checking substring references.

-fmax-stack-var-size=n
This option specifies the size in bytes of the largest array that will be put on the stack.

This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables. Future versions of gfortran may improve this behavior.

The default value for n is 32768.

-fpackderived
This option tells gfortran to pack derived type members as closely as possible. Code compiled with this option is likely to be incompatible with code compiled without this option, and may execute slower.
-frepack-arrays
In some circumstances gfortran may pass assumed shape array sections via a descriptor describing a discontiguous 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 discontiguous.

 

ENVIRONMENT

GNU Fortran 95 currently does not make use of any environment variables to control its operation above and beyond those that affect the operation of gcc.  

BUGS

For instructions on reporting bugs, see <http://gcc.gnu.org/bugs.html>.  

SEE ALSO

gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(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 GFORTRAN.  

COPYRIGHT

Copyright (c) 2004 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.2 or any later version published by the Free Software Foundation; with the Invariant Sections being ``GNU General Public License'' and ``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.


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
Options Controlling Fortran Dialect
Options to Request or Suppress Warnings
Options for Debugging Your Program or GNU Fortran
Options for Directory Search
Options for Code Generation Conventions
ENVIRONMENT
BUGS
SEE ALSO
AUTHOR
COPYRIGHT
blog comments powered by Disqus