3.6.4 Options for Controlling Warnings and Errors

Warnings are diagnostic messages which 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.

Table 3-12. Warning and Error Options Implied By All Warnings
Option

(links to explanatory section)

Controls
-pedanticWarnings demanded by strict ANSI C; rejects all programs that use forbidden extensions.
-pedantic-errorsWarnings implied by -pedantic, except that errors are produced rather than warnings.
-f[no-]syntax-onlyChecking code for syntax errors only.
-W[no-]msgWhether a message is enabled or disabled.
-wSuppression of all warning messages.
-W[no-]allEnablement of all warnings.
-W[no-]addressWarnings from suspicious use of memory addresses.
-W[no-]char-subscriptsWarnings from array subscripts with type char.
-W[no-]commentWarnings from suspicious comments.
-W[no-]div-by-zeroWarnings from compile-time integer division by zero.
-W[no-]formatWarnings from inappropriate printf() arguments.
-W[no-]implicitWarnings implied by both -Wimplicit-int and -Wimplicit-function-declaration.
-W[no-]implicit-function-
declarationWarnings from use of undeclared function.
-W[no-]implicit-intWarnings from declarations not specifying a type.
-W[no-]mainWarnings from unusual main definition.
-W[no-]missing-bracesWarnings from missing braces.
-W[no-]multicharWarnings from multi-character constant.
-W[no-]parenthesesWarnings from missing precedence.
-W[no-]return-typeWarnings from missing return type.
-W[no-]sequence-pointWarnings from sequence point violations.
-W[no-]switchWarnings from missing or extraneous case values.
-W[no-]system-headersWarnings from code within system headers.
-W[no-]trigraphsWarnings from use of trigraphs.
-W[no-]uninitializedWarnings from use of uninitialized variables.
-W[no-]unknown-pragmasWarnings from use of unknown pragma.
-W[no-]unusedWarnings from unused objects and constructs.
-W[no-]unused-functionWarnings from unused static function.
-W[no-]unused-labelWarnings from unused labels.
-W[no-]unused-parameterWarnings from unused parameter.
-W[no-]unused-variableWarnings from unused variable.
-W[no-]unused-valueWarnings from unused value.
Table 3-13. Warning Options Not Implied by All Warnings
OptionControls
-W[no-]extraThe generation of additional warning messages.
-W[no-]aggregate-returnWarnings from aggregate objects being returned.
-W[no-]bad-function-castWarnings from functions cast to a non-matching type.
-W[no-]cast-qualWarnings from discarded pointer qualifiers.
-W[no-]conversionWarnings from implicit conversions that can alter values.
-W[no-]errorGeneration of errors instead of warnings for dubious constructs.
-W[no-]inlineWarnings when functions cannot be in-lined.
-W[no-]larger-than=lenWarnings when defining large objects.
-W[no-]long-longWarnings from use of long long.
-W[no-]missing-declarationsWarnings when functions are not declared.
-W[no-]missing-
 format-attributeWarnings with missing format attributes.
-W[no-]missing-noreturnWarnings from potential noreturn attribute omissions.
-W[no-]missing-prototypesWarnings when functions are not declared with prototype.
-W[no-]nested-externsWarnings from extern declarations.
-Wno-deprecated-
 declarationsWhether warnings are produced for deprecated declarations.
-W[no-]pointer-arithWarnings when taking size of unsized types.
-W[no-]redundant-declsWarnings from redundant declarations.
-W[no-]shadowWarnings when local objects shadow other objects.
-W[no-]sign-compareWarnings from signed comparisons.
-W[no-]strict-prototypesWarnings from K&R function declarations.
-W[no-]traditionalWarnings from traditional differences.
-W[no-]undefWarnings from undefined identifiers.
-W[no-]unreachable-codeWarnings from unreachable code.
-W[no-]write-stringsWarnings when using non-const string pointers.