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
-Wimplicit to request warnings on implicit
declarations. Each of these specific warning options also has a
negative form beginning
-Wno- to turn off warnings;
-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:
-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
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
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, except that errors are produced rather than warnings.
-pedantic, but applies only to Fortran constructs.
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.
IMPLICIT NONEstatement in every program unit. (Some Fortran compilers provide this feature by an option named
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
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.
-Wuninitializedoptions 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
g77some might be added to the list enabled by
-W... options are not implied by
because they warn about constructions that we consider reasonable to
use, on occasion, in clean programs.
X*-Y. Such a construct is nonstandard, and can produce unexpected results in more complicated situations such as
g77along with many other compilers, interprets this example differently than many programmers, and a few other compilers. Specifically,
(X**(-Y))*Z, while others might think it should be interpreted as
A revealing example is the constant expression
g77 evaluates to .25, while others might evaluate
it to 0., the difference resulting from the way precedence affects
-fpedantic option also warns about expressions
having two arithmetic operators in a row.)
-2**2produces 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
-2147483648 and S holds
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,
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
DOvariables that are not of integral type--that is, using
REALvariables as loop control variables. Although such loops can be written to work in the "obvious" way, the way
g77is 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
DOloops, but the differences are pronounced for non-integral loop control variables.)
See Loops, for more information.
-Wuninitializedoption. (This might change in future versions of
"Extra warnings" are issued for:
-Wunusedalso is specified).
See Options to Request or Suppress Warnings, for information on more
by the GBE shared by
gcc and other GNU compilers.
Some of these have no effect when compiling programs written in Fortran: