/W, /w (Set Warning Level)

Options

/W{0|1|2|3|4|X}

/w

You can control the number of warning messages produced by the compiler by using the /w, /W0, /W1, /W2, /W3, /W4, or /WX option. A space between /W and 0, 1, 2, 3, 4, or X is optional. Compiler warning messages are any messages beginning with C4; see the Comprehensive Index and Errors Reference for a complete list of these messages.

Warnings indicate potential problems (rather than actual coding errors) with statements that may not compile as you intend.

The /W options affect only source files named on the command line; they do not apply to object files.

The following table describes the warning-level options. W1 warnings are the most serious and W4 warnings are the least serious:

Option Action

/w Turns off all warning messages. Use this option when you compile programs that deliberately include questionable statements. The /w option applies to the remainder of the command line or until the next occurrence of a /w option on the command line. /W0 and /W are the same as /w.
/W1 Default. Displays severe warning messages.
/W2 Displays an intermediate level of warning messages. Level 2 includes warnings such as the following:
  Use of functions with no declared return type.
  Failure to put return statements in functions with nonvoid return types.
  Data conversions that would cause loss of data or precision.
/W3 Displays a less severe level of warning messages, including warnings about function calls that precede their function prototypes in the source code.
/W4 Displays the least severe level of warning messages, including warnings about the use of non-ANSI features and extended keywords.
/WX Treats all warnings as errors. If there are any warning messages, an error message is emitted and compilation continues.

Note:

The descriptions of the warning messages in the Comprehensive Index and Errors Reference indicate the warning level that must be set (that is, the number for the appropriate /W option) for the message to appear.

Example

CL /W4 CRUNCH.C PRINT.C

This example enables all possible warning messages when the source files CRUNCH.C and PRINT.C are compiled. Microsoft C/C++ provides a pragma to control warning messages. For more information on #pragma warning, see Chapter 7, “Preprocessor Dircectives and Pragmas,” in the C Language Reference.