GNU Info

Info Node: (g77-295.info)Warning Options

(g77-295.info)Warning Options


Next: Debugging Options Prev: Fortran Dialect Options Up: Invoking G77
Enter node , (file) or (file)node

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 ANSI FORTRAN 77.
     `-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 ANSI FORTRAN 77 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 strict ANSI
     conformance.  They soon find that it does not do quite what they
     want--it finds some non-ANSI practices, but not all.  However,
     improvements to `g77' in this area are welcome.

`-pedantic-errors'
     Like `-pedantic', except that errors are produced rather than
     warnings.

`-fpedantic'
     Like `-pedantic', but applies only to Fortran constructs.

`-w'
     Inhibit all warning messages.

`-Wno-globals'
     Inhibit warnings about use of a name as both a global name (a
     subroutine, function, or block data program unit, or a common
     block) and implicitly as the name of an intrinsic in a source file.

     Also inhibit warnings about inconsistent invocations and/or
     definitions of global procedures (function and subroutines).  Such
     inconsistencies include different numbers of arguments and
     different types of arguments.

`-Wimplicit'
     Warn whenever a variable, array, or function is implicitly
     declared.  Has an effect similar to using the `IMPLICIT NONE'
     statement in every program unit.  (Some Fortran compilers provide
     this feature by an option named `-u' or `/WARNINGS=DECLARATIONS'.)

`-Wunused'
     Warn whenever a variable is unused aside from its declaration.

`-Wuninitialized'
     Warn whenever an automatic variable is used without first being
     initialized.

     These warnings are possible only in optimizing compilation,
     because they require data-flow information that is computed only
     when optimizing.  If you don't specify `-O', you simply won't get
     these warnings.

     These warnings occur only for variables that are candidates for
     register allocation.  Therefore, they do not occur for a variable
     whose address is taken, or whose size is other than 1, 2, 4 or 8
     bytes.  Also, they do not occur for arrays, even when they are in
     registers.

     Note that there might be no warning about a variable that is used
     only to compute a value that itself is never used, because such
     computations may be deleted by data-flow analysis before the
     warnings are printed.

     These warnings are made optional because GNU Fortran is not smart
     enough to see all the reasons why the code might be correct
     despite appearing to have an error.  Here is one example of how
     this can happen:

          SUBROUTINE DISPAT(J)
          IF (J.EQ.1) I=1
          IF (J.EQ.2) I=4
          IF (J.EQ.3) I=5
          CALL FOO(I)
          END

     If the value of `J' is always 1, 2 or 3, then `I' is always
     initialized, but GNU Fortran doesn't know this.  Here is another
     common case:

          SUBROUTINE MAYBE(FLAG)
          LOGICAL FLAG
          IF (FLAG) VALUE = 9.4
          ...
          IF (FLAG) PRINT *, VALUE
          END

     This has no bug because `VALUE' is used only if it is set.

`-Wall'
     The `-Wunused' and `-Wuninitialized' options combined.  These are
     all the options which pertain to usage that we recommend avoiding
     and that we believe is easy to avoid.  (As more warnings are added
     to `g77', some might be added to the list enabled by `-Wall'.)

   The remaining `-W...' options are not implied by `-Wall' because
they warn about constructions that we consider reasonable to use, on
occasion, in clean programs.

`-Wsurprising'
     Warn about "suspicious" constructs that are interpreted by the
     compiler in a way that might well be surprising to someone reading
     the code.  These differences can result in subtle,
     compiler-dependent (even machine-dependent) behavioral differences.
     The constructs warned about include:

        * Expressions having two arithmetic operators in a row, such as
          `X*-Y'.  Such a construct is nonstandard, and can produce
          unexpected results in more complicated situations such as
          `X**-Y*Z'.  `g77', along with many other compilers, interprets
          this example differently than many programmers, and a few
          other compilers.  Specifically, `g77' interprets `X**-Y*Z' as
          `(X**(-Y))*Z', while others might think it should be
          interpreted as `X**(-(Y*Z))'.

          A revealing example is the constant expression `2**-2*1.',
          which `g77' evaluates to .25, while others might evaluate it
          to 0., the difference resulting from the way precedence
          affects type promotion.

          (The `-fpedantic' option also warns about expressions having
          two arithmetic operators in a row.)

        * Expressions with a unary minus followed by an operand and then
          a binary operator other than plus or minus.  For example,
          `-2**2' produces a warning, because the precedence is
          `-(2**2)', yielding -4, not `(-2)**2', which yields 4, and
          which might represent what a programmer expects.

          An example of an expression producing different results in a
          surprising way is `-I*S', where I holds the value
          `-2147483648' and S holds `0.5'.  On many systems, negating I
          results in the same value, not a positive number, because it
          is already the lower bound of what an `INTEGER(KIND=1)'
          variable can hold.  So, the expression evaluates to a
          positive number, while the "expected" interpretation,
          `(-I)*S', would evaluate to a negative number.

          Even cases such as `-I*J' produce warnings, even though, in
          most configurations and situations, there is no computational
          difference between the results of the two
          interpretations--the purpose of this warning is to warn about
          differing interpretations and encourage a better style of
          coding, not to identify only those places where bugs might
          exist in the user's code.

        * `DO' loops with `DO' variables that are not of integral
          type--that is, using `REAL' variables as loop control
          variables.  Although such loops can be written to work in the
          "obvious" way, the way `g77' is required by the Fortran
          standard to interpret such code is likely to be quite
          different from the way many programmers expect.  (This is
          true of all `DO' loops, but the differences are pronounced
          for non-integral loop control variables.)

          Note: Loops, for more information.

`-Werror'
     Make 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 `g77'.)

     "Extra warnings" are issued for:

        * Unused parameters to a procedure (when `-Wunused' also is
          specified).

        * Overflows involving floating-point constants (not available
          for certain configurations).

   Note: Options to Request or Suppress Warnings,
for information on more options offered by the GBE shared by `g77',
`gcc', and other GNU compilers.

   Some of these have no effect when compiling programs written in
Fortran:

`-Wcomment'

`-Wformat'

`-Wparentheses'

`-Wswitch'

`-Wtraditional'

`-Wshadow'

`-Wid-clash-LEN'

`-Wlarger-than-LEN'

`-Wconversion'

`-Waggregate-return'

`-Wredundant-decls'
     These options all could have some relevant meaning for GNU Fortran
     programs, but are not yet supported.


automatically generated by info2www version 1.2.2.9