1 @c Copyright (C) 2004, 2005
2 @c Free Software Foundation, Inc.
3 @c This is part of the GFORTRAN manual.
4 @c For copying conditions, see the file gfortran.texi.
8 Copyright @copyright{} 2004, 2005
9 Free Software Foundation, Inc.
11 Permission is granted to copy, distribute and/or modify this document
12 under the terms of the GNU Free Documentation License, Version 1.2 or
13 any later version published by the Free Software Foundation; with the
14 Invariant Sections being ``GNU General Public License'' and ``Funding
15 Free Software'', the Front-Cover texts being (a) (see below), and with
16 the Back-Cover Texts being (b) (see below). A copy of the license is
17 included in the gfdl(7) man page.
19 (a) The FSF's Front-Cover Text is:
23 (b) The FSF's Back-Cover Text is:
25 You have freedom to copy and modify this GNU Manual, like GNU
26 software. Copies published by the Free Software Foundation raise
27 funds for GNU development.
29 @c Set file name and title for the man page.
31 @settitle GNU Fortran 95 compiler.
33 gfortran [@option{-c}|@option{-S}|@option{-E}]
34 [@option{-g}] [@option{-pg}] [@option{-O}@var{level}]
35 [@option{-W}@var{warn}@dots{}] [@option{-pedantic}]
36 [@option{-I}@var{dir}@dots{}] [@option{-L}@var{dir}@dots{}]
37 [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
38 [@option{-f}@var{option}@dots{}]
39 [@option{-m}@var{machine-option}@dots{}]
40 [@option{-o} @var{outfile}] @var{infile}@dots{}
42 Only the most useful options are listed here; see below for the
46 gpl(7), gfdl(7), fsf-funding(7),
47 cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1)
48 and the Info entries for @file{gcc}, @file{cpp}, @file{gfortran}, @file{as},
49 @file{ld}, @file{binutils} and @file{gdb}.
52 For instructions on reporting bugs, see
53 @w{@uref{http://gcc.gnu.org/bugs.html}}.
56 See the Info entry for @command{gfortran} for contributors to GCC and
61 @node Invoking GFORTRAN
62 @chapter GNU Fortran 95 Command Options
63 @cindex GNU Fortran 95 command options
64 @cindex command options
65 @cindex options, GNU Fortran 95 command
67 @c man begin DESCRIPTION
69 The @command{gfortran} command supports all the options supported by the
70 @command{gcc} command. Only options specific to gfortran are documented here.
72 @xref{Invoking GCC,,GCC Command Options,gcc,Using the GNU Compiler
73 Collection (GCC)}, for information
74 on the non-Fortran-specific aspects of the @command{gcc} command (and,
75 therefore, the @command{gfortran} command).
77 @cindex options, negative forms
78 @cindex negative forms of options
79 All @command{gcc} and @command{gfortran} options
80 are accepted both by @command{gfortran} and by @command{gcc}
81 (as well as any other drivers built at the same time,
82 such as @command{g++}),
83 since adding @command{gfortran} to the @command{gcc} distribution
84 enables acceptance of @command{gfortran} options
85 by all of the relevant drivers.
87 In some cases, options have positive and negative forms;
88 the negative form of @option{-ffoo} would be @option{-fno-foo}.
89 This manual documents only one of these two forms, whichever
90 one is not the default.
94 * Option Summary:: Brief list of all @command{gfortran} options,
96 * Fortran Dialect Options:: Controlling the variant of Fortran language
98 * Warning Options:: How picky should the compiler be?
99 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
100 * Directory Options:: Where to find module files
101 * Code Gen Options:: Specifying conventions for function calls, data layout
103 * Environment Variables:: Env vars that affect GNU Fortran.
107 @section Option Summary
111 Here is a summary of all the options specific to GNU Fortran, grouped
112 by type. Explanations are in the following sections.
115 @item Fortran Language Options
116 @xref{Fortran Dialect Options,,Options Controlling Fortran Dialect}.
118 -ffree-form -fno-fixed-form @gol
119 -fdollar-ok -fimplicit-none -fmax-identifier-length @gol
121 -ffixed-line-length-@var{n} -ffixed-line-length-none @gol
122 -fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 }
124 @item Warning Options
125 @xref{Warning Options,,Options to Request or Suppress Warnings}.
127 -fsyntax-only -pedantic -pedantic-errors @gol
128 -w -Wall -Waliasing -Wconversion @gol
129 -Wimplicit-interface -Wnonstd-intrinsics -Wsurprising -Wunderflow @gol
130 -Wunused-labels -Wline-truncation @gol
133 @item Debugging Options
134 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
138 @item Directory Options
139 @xref{Directory Options,,Options for Directory Search}.
141 -I@var{dir} -M@var{dir}}
143 @item Code Generation Options
144 @xref{Code Gen Options,,Options for Code Generation Conventions}.
146 -ff2c -fno-underscoring -fsecond-underscore @gol
147 -fbounds-check -fmax-stack-var-size=@var{n} @gol
148 -fpackderived -frepack-arrays}
152 * Fortran Dialect Options:: Controlling the variant of Fortran language
154 * Warning Options:: How picky should the compiler be?
155 * Debugging Options:: Symbol tables, measurements, and debugging dumps.
156 * Directory Options:: Where to find module files
157 * Code Gen Options:: Specifying conventions for function calls, data layout
161 @node Fortran Dialect Options
162 @section Options Controlling Fortran Dialect
163 @cindex dialect options
164 @cindex language, dialect options
165 @cindex options, dialect
167 The following options control the dialect of Fortran
168 that the compiler accepts:
171 @cindex -ffree-form option
172 @cindex options, -ffree-form
173 @cindex -fno-fixed-form option
174 @cindex options, -fno-fixed-form
175 @cindex source file format
179 @cindex Fortran 90, features
182 Specify the layout used by the the source file. The free form layout
183 was introduced in Fortran 90. Fixed form was traditionally used in
184 older Fortran programs.
186 @cindex option, -fdefault-double-8
187 @cindex -fdefault-double-8, option
188 @item -fdefault-double-8
189 Set the "DOUBLE PRECISION" type to an 8 byte wide.
191 @cindex option, -fdefault-integer-8
192 @cindex -fdefault-integer-8, option
193 @item -fdefault-integer-8
194 Set the default integer and logical types to an 8 byte wide type.
195 Do nothing if this is already the default.
197 @cindex option, -fdefault-real-8
198 @cindex -fdefault-real-8, option
199 @item -fdefault-real-8
200 Set the default real type to an 8 byte wide type.
201 Do nothing if this is already the default.
203 @cindex -fdollar-ok option
204 @cindex options, -fdollar-ok
208 @cindex character set
209 Allow @samp{$} as a valid character in a symbol name.
211 @cindex -fno-backslash option
212 @cindex options, -fno-backslash
215 @cindex escape characters
217 Compile switch to change the interpretation of a backslash from
218 ``C''-style escape characters to a single backslash character.
220 @cindex -ffixed-line-length-@var{n} option
221 @cindex options, -ffixed-line-length-@var{n}
222 @item -ffixed-line-length-@var{n}
223 @cindex source file format
224 @cindex lines, length
225 @cindex length of source lines
227 @cindex limits, lengths of source lines
228 Set column after which characters are ignored in typical fixed-form
229 lines in the source file, and through which spaces are assumed (as
230 if padded to that length) after the ends of short fixed-form lines.
233 @cindex extended-source option
234 Popular values for @var{n} include 72 (the
235 standard and the default), 80 (card image), and 132 (corresponds
236 to ``extended-source'' options in some popular compilers).
237 @var{n} may be @samp{none}, meaning that the entire line is meaningful
238 and that continued character constants never have implicit spaces appended
239 to them to fill out the line.
240 @option{-ffixed-line-length-0} means the same thing as
241 @option{-ffixed-line-length-none}.
243 @cindex -fmax-identifier-length=@var{n} option
244 @cindex option -fmax-identifier-length=@var{n}
245 @item -fmax-identifier-length=@var{n}
246 Specify the maximum allowed identifier length. Typical values are
247 31 (Fortran 95) and 63 (Fortran 200x).
249 @cindex -fimplicit-none option
250 @cindex options, -fimplicit-none
251 @item -fimplicit-none
252 Specify that no implicit typing is allowed, unless overridden by explicit
253 @samp{IMPLICIT} statements. This is the equivalent of adding
254 @samp{implicit none} to the start of every procedure.
256 @cindex -std=@var{std} option
257 @cindex option, -std=@var{std}
259 Conform to the specified standard. Allowed values for @var{std} are
260 @samp{gnu}, @samp{f95}, @samp{f2003} and @samp{legacy}.
264 @node Warning Options
265 @section Options to Request or Suppress Warnings
266 @cindex options, warnings
267 @cindex warnings, suppressing
268 @cindex messages, warning
269 @cindex suppressing warnings
271 Warnings are diagnostic messages that report constructions which
272 are not inherently erroneous but which are risky or suggest there
273 might have been an error.
275 You can request many specific warnings with options beginning @option{-W},
276 for example @option{-Wimplicit} to request warnings on implicit
277 declarations. Each of these specific warning options also has a
278 negative form beginning @option{-Wno-} to turn off warnings;
279 for example, @option{-Wno-implicit}. This manual lists only one of the
280 two forms, whichever is not the default.
282 These options control the amount and kinds of warnings produced by GNU
286 @cindex syntax checking
287 @cindex -fsyntax-only option
288 @cindex options, -fsyntax-only
290 Check the code for syntax errors, but don't do anything beyond that.
292 @cindex -pedantic option
293 @cindex options, -pedantic
295 Issue warnings for uses of extensions to FORTRAN 95.
296 @option{-pedantic} also applies to C-language constructs where they
297 occur in GNU Fortran source files, such as use of @samp{\e} in a
298 character constant within a directive like @samp{#include}.
300 Valid FORTRAN 95 programs should compile properly with or without
302 However, without this option, certain GNU extensions and traditional
303 Fortran features are supported as well.
304 With this option, many of them are rejected.
306 Some users try to use @option{-pedantic} to check programs for conformance.
307 They soon find that it does not do quite what they want---it finds some
308 nonstandard practices, but not all.
309 However, improvements to @command{gfortran} in this area are welcome.
311 This should be used in conjunction with -std=@var{std}.
313 @cindex -pedantic-errors option
314 @cindex options, -pedantic-errors
315 @item -pedantic-errors
316 Like @option{-pedantic}, except that errors are produced rather than
322 Inhibit all warning messages.
326 @cindex options, -Wall
329 @cindex warnings, all
330 Enables commonly used warning options that which pertain to usage that
331 we recommend avoiding and that we believe is easy to avoid.
332 This currently includes @option{-Wunused-labels}, @option{-Waliasing},
333 @option{-Wsurprising}, @option{-Wnonstd-intrinsic} and
334 @option{-Wline-truncation}.
337 @cindex -Waliasing option
338 @cindex options, -Waliasing
341 Warn about possible aliasing of dummy arguments. Specifically, it warns
342 if the same actual argument is associated with a dummy argument with
343 @code{intent(in)} and a dummy argument with @code{intent(out)} in a call
344 with an explicit interface.
346 The following example will trigger the warning.
350 integer, intent(in) :: a
351 integer, intent(out) :: b
360 @cindex -Wconversion option
361 @cindex options, -Wconversion
364 Warn about implicit conversions between different types.
367 @cindex -Wimplicit-interface option
368 @cindex options, -Wimplicit-interface
369 @item -Wimplicit-interface
370 Warn about when procedure are called without an explicit interface.
371 Note this only checks that an explicit interface is present. It does not
372 check that the declared interfaces are consistent across program units.
375 @cindex -Wnonstd-intrinsic option
376 @cindex options, -Wnonstd-intrinsic
377 @item -Wnonstd-intrinsic
378 Warn if the user tries to use an intrinsic that does not belong to the
379 standard the user has chosen via the -std option.
383 @cindex options, -Wsurprising
386 Produce a warning when ``suspicious'' code constructs are encountered.
387 While technically legal these usually indicate that an error has been made.
389 This currently produces a warning under the following circumstances:
393 An INTEGER SELECT construct has a CASE that can never be matched as its
394 lower value is greater than its upper value.
397 A LOGICAL SELECT construct has three CASE statements.
401 @cindex options, -Wunderflow
404 Produce a warning when numerical constant expressions are
405 encountered, which yield an UNDERFLOW during compilation.
408 @cindex -Wunused-labels option
409 @cindex options, -Wunused-labels
410 @item -Wunused-labels
411 @cindex unused labels
412 @cindex labels, unused
413 Warn whenever a label is defined but never referenced.
417 @cindex options, -Werror
419 Turns all warnings into errors.
425 @cindex extra warnings
426 @cindex warnings, extra
427 Turns on ``extra warnings'' and, if optimization is specified
428 via @option{-O}, the @option{-Wuninitialized} option.
429 (This might change in future versions of @command{gfortran}
432 @xref{Warning Options,,Options to Request or Suppress Warnings,
433 gcc,Using the GNU Compiler Collection (GCC)}, for information on more
434 options offered by the GBE shared by @command{gfortran}, @command{gcc} and
437 Some of these have no effect when compiling programs written in Fortran.
439 @node Debugging Options
440 @section Options for Debugging Your Program or GNU Fortran
441 @cindex options, debugging
442 @cindex debugging information options
444 GNU Fortran has various special options that are used for debugging
445 either your program or @command{gfortran}
448 @cindex -fdump-parse-tree option
449 @cindex option, -fdump-parse-tree
450 @item -fdump-parse-tree
451 Output the internal parse tree before starting code generation. Only
452 really useful for debugging gfortran itself.
455 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
456 gcc,Using the GNU Compiler Collection (GCC)}, for more information on
459 @node Directory Options
460 @section Options for Directory Search
461 @cindex directory, options
462 @cindex options, directory search
465 @cindex INCLUDE directive
466 @cindex directive, INCLUDE
467 There options affect how affect how @command{gfortran} searches
468 for files specified via the @code{INCLUDE} directive, and where it searches
469 for previously compiled modules.
471 It also affects the search paths used by @command{cpp} when used to preprocess
476 @cindex options, -Idir
478 @cindex directory, search paths for inclusion
479 @cindex inclusion, directory search paths for
480 @cindex search paths, for included files
481 @cindex paths, search
482 @cindex module search path
483 These affect interpretation of the @code{INCLUDE} directive
484 (as well as of the @code{#include} directive of the @command{cpp}
487 Also note that the general behavior of @option{-I} and
488 @code{INCLUDE} is pretty much the same as of @option{-I} with
489 @code{#include} in the @command{cpp} preprocessor, with regard to
490 looking for @file{header.gcc} files and other such things.
492 This path is also used to search for @samp{.mod} files when previously
493 compiled modules are required by a @code{USE} statement.
495 @xref{Directory Options,,Options for Directory Search,
496 gcc,Using the GNU Compiler Collection (GCC)}, for information on the
500 @cindex option, -Mdir
503 This option specifies where to put @samp{.mod} files for compiled modules.
504 It is also added to the list of directories to searched by an @code{USE}
507 The default is the current directory.
509 @option{-J} is an alias for @option{-M} to avoid conflicts with existing
513 @node Code Gen Options
514 @section Options for Code Generation Conventions
515 @cindex code generation, conventions
516 @cindex options, code generation
517 @cindex run-time, options
519 These machine-independent options control the interface conventions
520 used in code generation.
522 Most of them have both positive and negative forms; the negative form
523 of @option{-ffoo} would be @option{-fno-foo}. In the table below, only
524 one of the forms is listed---the one which is not the default. You
525 can figure out the other form by either removing @option{no-} or adding
530 @cindex @option{-ff2c} option
531 @cindex options, @option{-ff2c}
533 @cindex calling convention
534 @cindex @command{f2c} calling convention
535 @cindex @command{g77} calling convention
536 @cindex libf2c calling convention
537 Generate code designed to be compatible with code generated
538 by @command{g77} and @command{f2c}.
540 The calling conventions used by @command{g77} (originally implemented
541 in @command{f2c}) require functions that return type
542 default @code{REAL} to actually return the C type @code{double}, and
543 functions that return type @code{COMPLEX} to return the values via an
544 extra argument in the calling sequence that points to where to
545 store the return value. Under the default GNU calling conventions, such
546 functions simply return their results as they would in GNU
547 C -- default @code{REAL} functions return the C type @code{float}, and
548 @code{COMPLEX} functions return the GNU C type @code{complex}.
549 Additionally, this option implies the @option{-fsecond-underscore}
550 option, unless @option{-fno-second-underscore} is explicitly requested.
552 This does not affect the generation of code that interfaces with
553 the @command{libgfortran} library.
555 @emph{Caution:} It is not a good idea to mix Fortran code compiled
556 with @code{-ff2c} with code compiled with the default @code{-fno-f2c}
557 calling conventions as, calling @code{COMPLEX} or default @code{REAL}
558 functions between program parts which were compiled with different
559 calling conventions will break at execution time.
561 @emph{Caution:} This will break code which passes intrinsic functions
562 of type default @code{REAL} or @code{COMPLEX} as actual arguments, as
563 the library implementations use the @command{-fno-f2c} calling conventions.
565 @cindex @option{-fno-underscoring option}
566 @cindex options, @option{-fno-underscoring}
567 @item -fno-underscoring
569 @cindex symbol names, underscores
570 @cindex transforming symbol names
571 @cindex symbol names, transforming
572 Do not transform names of entities specified in the Fortran
573 source file by appending underscores to them.
575 With @option{-funderscoring} in effect, @command{gfortran} appends one
576 underscore to external names with no underscores.
578 This is done to ensure compatibility with code produced by many
579 UNIX Fortran compilers.
581 @emph{Caution}: The default behavior of @command{gfortran} is
582 incompatible with @command{f2c} and @command{g77}, please use the
583 @option{-ff2c} option if you want object files compiled with
584 @option{gfortran} to be compatible with object code created with these
587 Use of @option{-fno-underscoring} is not recommended unless you are
588 experimenting with issues such as integration of (GNU) Fortran into
589 existing system environments (vis-a-vis existing libraries, tools, and
592 For example, with @option{-funderscoring}, and assuming other defaults like
593 @option{-fcase-lower} and that @samp{j()} and @samp{max_count()} are
594 external functions while @samp{my_var} and @samp{lvar} are local variables,
598 I = J() + MAX_COUNT (MY_VAR, LVAR)
602 is implemented as something akin to:
605 i = j_() + max_count__(&my_var__, &lvar);
608 With @option{-fno-underscoring}, the same statement is implemented as:
611 i = j() + max_count(&my_var, &lvar);
614 Use of @option{-fno-underscoring} allows direct specification of
615 user-defined names while debugging and when interfacing @command{gfortran}
616 code with other languages.
618 Note that just because the names match does @emph{not} mean that the
619 interface implemented by @command{gfortran} for an external name matches the
620 interface implemented by some other language for that same name.
621 That is, getting code produced by @command{gfortran} to link to code produced
622 by some other compiler using this or any other method can be only a
623 small part of the overall solution---getting the code generated by
624 both compilers to agree on issues other than naming can require
625 significant effort, and, unlike naming disagreements, linkers normally
626 cannot detect disagreements in these other areas.
628 Also, note that with @option{-fno-underscoring}, the lack of appended
629 underscores introduces the very real possibility that a user-defined
630 external name will conflict with a name in a system library, which
631 could make finding unresolved-reference bugs quite difficult in some
632 cases---they might occur at program run time, and show up only as
633 buggy behavior at run time.
635 In future versions of @command{gfortran} we hope to improve naming and linking
636 issues so that debugging always involves using the names as they appear
637 in the source, even if the names as seen by the linker are mangled to
638 prevent accidental linking between procedures with incompatible
641 @cindex @option{-fsecond-underscore option}
642 @cindex options, @option{-fsecond-underscore}
643 @item -fsecond-underscore
645 @cindex symbol names, underscores
646 @cindex transforming symbol names
647 @cindex symbol names, transforming
648 @cindex @command{f2c} calling convention
649 @cindex @command{g77} calling convention
650 @cindex libf2c calling convention
651 By default, @command{gfortran} appends an underscore to external
652 names. If this option is used @command{gfortran} appends two
653 underscores to names with underscores and one underscore to external names
654 with no underscores. (@command{gfortran} also appends two underscores to
655 internal names with underscores to avoid naming collisions with external
658 This option has no effect if @option{-fno-underscoring} is
659 in effect. It is implied by the @option{-ff2c} option.
661 Otherwise, with this option, an external name such as @samp{MAX_COUNT}
662 is implemented as a reference to the link-time external symbol
663 @samp{max_count__}, instead of @samp{max_count_}. This is required
664 for compatibility with @command{g77} and @command{f2c}, and is implied
665 by use of the @option{-ff2c} option.
668 @cindex -fbounds-check option
669 @cindex -ffortran-bounds-check option
671 @cindex bounds checking
672 @cindex range checking
673 @cindex array bounds checking
674 @cindex subscript checking
675 @cindex checking subscripts
676 Enable generation of run-time checks for array subscripts
677 and against the declared minimum and maximum values. It also
678 checks array indices for assumed and deferred
679 shape arrays against the actual allocated bounds.
681 In the future this may also include other forms of checking, eg. checking
682 substring references.
685 @cindex -fmax-stack-var-size option
686 @item -fmax-stack-var-size=@var{n}
687 This option specifies the size in bytes of the largest array that will be put
690 This option currently only affects local arrays declared with constant
691 bounds, and may not apply to all character variables.
692 Future versions of @command{gfortran} may improve this behavior.
694 The default value for @var{n} is 32768.
696 @cindex -fpackderived
698 @cindex Structure packing
699 This option tells gfortran to pack derived type members as closely as
700 possible. Code compiled with this option is likely to be incompatible
701 with code compiled without this option, and may execute slower.
703 @cindex -frepack-arrays option
704 @item -frepack-arrays
705 @cindex Repacking arrays
706 In some circumstances @command{gfortran} may pass assumed shape array
707 sections via a descriptor describing a discontiguous area of memory.
708 This option adds code to the function prologue to repack the data into
709 a contiguous block at runtime.
711 This should result in faster accesses to the array. However it can introduce
712 significant overhead to the function call, especially when the passed data
716 @xref{Code Gen Options,,Options for Code Generation Conventions,
717 gcc,Using the GNU Compiler Collection (GCC)}, for information on more options
719 shared by @command{gfortran} @command{gcc} and other GNU compilers.
724 @node Environment Variables
725 @section Environment Variables Affecting GNU Fortran
726 @cindex environment variables
728 @c man begin ENVIRONMENT
730 GNU Fortran 95 currently does not make use of any environment
731 variables to control its operation above and beyond those
732 that affect the operation of @command{gcc}.
734 @xref{Environment Variables,,Environment Variables Affecting GCC,
735 gcc,Using the GNU Compiler Collection (GCC)}, for information on environment