3.6.4 Options for Controlling Warnings and Errors
Warnings are diagnostic messages that report constructions that, while not inherently erroneous, indicate source code or some other situation is unusual and might lead to runtime failures of the code.
You can request specific warnings using options beginning with
-W
; for example, -Wimplicit
, to request warnings on
implicit declarations. Most of these specific warning options also have a negative form,
beginning with -Wno-
, to turn off warnings; for example,
-Wno-implicit
. These will be shown in the form a
-W[no-]warning
. Some only have a negative form,
which will be shown as a -Wno-warning
.
The options shown in the tables below are the more commonly used warning options that control messages issued by the compile. In the (linked) sections that follow, the options that affect warnings generally are discussed.
Option (links to explanatory section) |
Controls |
---|---|
-f[no-]syntax-only |
Checking code for syntax errors only. |
-pedantic |
Warnings demanded by strict ANSI C; rejects all programs that use forbidden extensions. |
-pedantic-errors |
Warnings implied by
-pedantic , except that errors are produced rather than
warnings. |
-w |
Suppression of all warning messages. |
-W[no-]all |
Enablement of all warnings. |
-W[no-]address |
Warnings from suspicious use of memory addresses. |
-W[no-]char-subscripts |
Warnings from array subscripts with type char. |
-W[no-]comment |
Warnings from suspicious comments. |
-W[no-]div-by-zero |
Warnings from compile-time integer division by zero. |
-W[no-]format |
Warnings from inappropriate
printf() arguments. |
-W[no-]implicit |
Warnings implied by both
-Wimplicit-int and
-Wimplicit-function-declaration . |
-W[no-]implicit-function-
declaration |
Warnings from use of undeclared function. |
-W[no-]implicit-int |
Warnings from declarations not specifying a type. |
-W[no-]main |
Warnings from unusual main definition. |
-W[no-]missing-braces |
Warnings from missing braces. |
-W[no-]multichar |
Warnings from multi-character constant. |
-W[no-]parentheses |
Warnings from missing precedence. |
-W[no-]return-type |
Warnings from missing return type. |
-W[no-]sequence-point |
Warnings from sequence point violations. |
-W[no-]switch |
Warnings from missing or extraneous case values. |
-W[no-]system-headers |
Warnings from code within system headers. |
-W[no-]trigraphs |
Warnings from use of trigraphs. |
-W[no-]uninitialized |
Warnings from use of uninitialized variables. |
-W[no-]unknown-pragmas |
Warnings from use of unknown pragma. |
-W[no-]unused |
Warnings from unused objects and constructs. |
-W[no-]unused-function |
Warnings from unused static function. |
-W[no-]unused-label |
Warnings from unused labels. |
-W[no-]unused-parameter |
Warnings from unused parameter. |
-W[no-]unused-variable |
Warnings from unused variable. |
-W[no-]unused-value |
Warnings from unused value. |
Option | Controls |
---|---|
-W[no-]extra |
The generation of additional warning messages. |
-W[no-]aggregate-return |
Warnings from aggregate objects being returned. |
-W[no-]bad-function-cast |
Warnings from functions cast to a non-matching type. |
-W[no-]cast-qual |
Warnings from discarded pointer qualifiers. |
-W[no-]conversion |
Warnings from implicit conversions that can alter values. |
-W[no-]error |
Generation of errors instead of warnings for dubious constructs. |
-W[no-]inline |
Warnings when functions cannot be in-lined. |
-W[no-]larger-than=len |
Warnings when defining large objects. |
-W[no-]long-long |
Warnings from use of long
long . |
-W[no-]missing-declarations |
Warnings when functions are not declared. |
-W[no-]missing-
format-attribute |
Warnings with missing format attributes. |
-W[no-]missing-noreturn |
Warnings from potential noreturn attribute omissions. |
-W[no-]missing-prototypes |
Warnings when functions are not declared with prototype. |
-W[no-]nested-externs |
Warnings from extern
declarations. |
-Wno-deprecated-
declarations |
Whether warnings are produced for deprecated declarations. |
-W[no-]pointer-arith |
Warnings when taking size of unsized types. |
-W[no-]redundant-decls |
Warnings from redundant declarations. |
-W[no-]shadow |
Warnings when local objects shadow other objects. |
-W[no-]sign-compare |
Warnings from signed comparisons. |
-W[no-]strict-prototypes |
Warnings from K&R function declarations. |
-W[no-]traditional |
Warnings from traditional differences. |
-W[no-]undef |
Warnings from undefined identifiers. |
-W[no-]unreachable-code |
Warnings from unreachable code. |
-W[no-]write-strings |
Warnings when using non-const string pointers. |