Next: Debugging Options, Previous: Fortran Dialect Options, Up: Invoking G77
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
-pedantic
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
-fpedantic
-w
-Wno-globals
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
IMPLICIT NONE
statement
in every program unit.
(Some Fortran compilers provide this feature by an option
named -u or `/WARNINGS=DECLARATIONS'.)
-Wunused
-Wuninitialized
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 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
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.)
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.)
See Loops, for more information.
-Werror
-W
“Extra warnings” are issued for:
See 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
-Wswitch-default
-Wswitch-enum
-Wtraditional
-Wshadow
-Wid-clash-
len-Wlarger-than-
len-Wconversion
-Waggregate-return
-Wredundant-decls