Expand Minimize

/w, /Wn, /WX, /Wall, /wln, /wdn, /wen, /won (Warning Level)

Specifies how the compiler generates warnings for a given compilation.

/w
/Wn
/WX
/Wall
/wln
/wdn
/wen
/won

The options and related arguments are described in the following table.

Option

Description

/w

Disables all compiler warnings.

/W n

Specifies the level of warning to be generated by the compiler. Valid warning levels for n range from 0 to 4:

  • Level 0 disables all warnings.

  • Level 1 displays severe warnings. Level 1 is the default setting.

  • Level 2 displays all level 1 warnings and warnings that are less severe than level 1.

  • Level 3 displays all level 2 warnings and all other warnings that are recommended for production purposes.

  • Level 4 displays all level 3 warnings and informational warnings. We recommend that you use this option only to provide lint-like warnings. However, for a new project, it may be best to use /W4 in all compilations; this will ensure the fewest possible hard-to-find code defects.

/Wall

Displays all /W4 warnings and any other warnings that are not included in /W4—for example, warnings that are off by default. See Compiler Warnings That Are Off By Default.

/WX

Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings will ensure the fewest possible hard-to-find code defects.

The linker also has a /WX option. See /WX (Treat Linker Warnings as Errors) for more information.

/w ln

Specifies the level for a particular warning. The first parameter sets the warning level (same as /Wn) and the second parameter is the actual warning number.

For example, /w14326 causes C4326 to be generated as a level 1 warning.

/wd n

Disables the compiler warning that is specified in n.

For example, /wd4326 disables compiler warning C4326.

/we n

Treats as an error the compiler warning that is specified in n.

For example, /we4326 flags warning number C4326 as an error.

/wo n

Reports the error only once for the compiler warning that is specified in n.

For example, /wo4326 causes warning C4326 to be reported only once.

If you create a precompiled header (/Yc (Create Precompiled Header File)) by using one of the /w options, any use of the precompiled header (/Yu (Use Precompiled Header File)) causes those same /w options to be in effect again. You can override the /w setting in the precompiled header by using another /w option on the command line.

Pragma directives in source code are unaffected by the /w option.

You can also use warning to control the level of warning that is reported at compile time.

The build errors documentation describes the warnings and warning levels, and indicates why certain statements may not compile as you intend.

To set the compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

  2. Select C/C++.

  3. On the General property page, modify the Warning Level or Treat Warnings as Errors properties.

  4. On the Advanced property page, modify the Disable Specific Warnings property.

  5. For the remaining options, on the Command Line property page, type the compiler option in the Additional Options box.

To set the compiler option programmatically

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft