7.6.4.1 Options to Control the Amount and Types of Warnings
The following options control the amount and kinds of warnings produced by the compiler.
Option | Definition |
---|---|
-fsyntax-only | Check the code for syntax, but don’t do anything beyond that. |
-w | Inhibit all warning messages. |
-Wall | All of the -W options
listed in this table combined. This enables all the warnings about
constructions that some users consider questionable, and that are easy
to avoid (or modify to prevent the warning), even in conjunction with
macros. |
-Wchar-subscripts | Warn if an array subscript has type
char . |
-Wcomment
| Warn whenever a comment-start sequence
/* appears in a /* comment, or
whenever a Backslash-Newline appears in a //
comment. |
-Wdiv-by-zero | Warn about compile-time integer
division by zero. To inhibit the warning messages, use
-Wno-div-by-zero . Floating point division by zero
is not warned about, as it can be a legitimate way of obtaining
infinities and NaNs.(This is the default.) |
-Werror-implicit-
function-declaration | Give an error whenever a function is used before being declared. |
-Wformat | Check calls to printf
and scanf , etc., to make sure that the arguments
supplied have types appropriate to the format string specified. |
-Wimplicit | Equivalent to specifying both
-Wimplicit-int and
-Wimplicit-function-declaration . |
-Wimplicit-function-
declaration | Give a warning whenever a function is used before being declared. |
-Wimplicit-int | Warn when a declaration does not specify a type. |
-Wmain | Warn if the type of
main is suspicious. main should be
a function with external linkage, returning int , taking
either zero, two or three arguments of appropriate types. |
-Wmissing-braces | Warn if an aggregate or union
initializer is not fully bracketed. In the following example, the
initializer for a is not fully bracketed, but that for
b is fully bracketed.
|
-Wmultichar
| Warn if a multi-character
char constant is used. Usually, such constants are
typographical errors. Since they have implementation-defined values,
they should not be used in portable code. The following example
illustrates the use of a multi-character char
constant:
|
-Wparentheses | Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often find confusing. |
-Wreturn-type | Warn whenever a function is defined
with a return-type that defaults to int . Also warn
about any return statement with no return-value in a
function whose return-type is not void . |
-Wsequence-point | Warn about code that may have undefined
semantics because of violations of sequence point rules in the C
standard. The C standard defines the order in
which expressions in a C program are evaluated in terms of sequence
points, which represent a partial ordering between the execution of
parts of the program: those executed before the sequence point and
those executed after it. These occur after the evaluation of a full
expression (one which is not part of a larger expression), after the
evaluation of the first operand of a It is not specified, when between sequence points modifications to the values of objects take effect. Programs whose behavior depends on this have undefined behavior; the C standard specifies that “Between the previous and next sequence point, an object shall have its stored value modified, at most once, by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.” If a program breaks these rules, the results on any particular implementation are entirely unpredictable. Examples of code with undefined behavior are |
-Wswitch | Warn whenever a switch
statement has an index of enumeral type and lacks a case for one or more
of the named codes of that enumeration. (The presence of a default label
prevents this warning.) case labels outside the
enumeration range also provoke warnings when this option is
used. |
-Wsystem-headers | Print warning messages for constructs
found in system header files. Warnings from system headers are normally
suppressed, on the assumption that they usually do not indicate real
problems and would only make the compiler output harder to read. Using
this command line option tells the compiler to emit warnings from system
headers as if they occurred in user code. However, note that using
-Wall in conjunction with this option will not warn
about unknown pragmas in system headers; for that,
-Wunknown-pragmas must also be used. |
-Wtrigraphs | Warn if any trigraphs are encountered (assuming they are enabled). |
-Wuninitialized | Warn if an automatic variable is used
without first being initialized. These warnings are possible only when optimization is enabled, because they require data flow information that is computed only when optimizing. These warnings occur only for variables that are
candidates for register allocation. Therefore, they do not occur for
a variable that is declared Note that there may 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. |
-Wunknown-pragmas | Warn when a #pragma
directive is encountered which is not understood by the compiler. If
this command line option is used, warnings will even be issued for
unknown pragmas in system header files. This is not the case if the
warnings were only enabled by the -Wall command line
option. |
-Wunused | Warn whenever a variable is unused
aside from its declaration, whenever a function is declared static but
never defined, whenever a label is declared but not used, and whenever a
statement computes a result that is explicitly not used. In order to get a warning about an unused function
parameter, both Casting an expression to
void suppresses this warning for an expression. Similarly, the
|
-Wunused-function | Warn whenever a static function is declared but not defined or a non-inline static function is unused. |
-Wunused-label | Warn whenever a label is declared but not used. To suppress this warning, use the unused attribute (see section Variable Attributes). |
-Wunused-variable | Warn whenever a local variable or non-constant static variable is unused aside from its declaration. To suppress this warning, use the unused attribute (see section Variable Attributes). |
-Wunused-value | Warn whenever a statement computes a
result that is explicitly not used. To suppress this warning, cast the
expression to void . |