INF: /WX Compiler Switch Behavior Determined by /W{0|1|2|3|4}

ID Number: Q69932

6.00 6.00a 6.00ax 7.00 | 6.00 6.00a

MS-DOS | OS/2

Summary:

The documentation for the /WX compiler option implies that the /WX

switch is a superset of /W4, and causes warnings of all levels to

suppress creation of the object (.OBJ) file. In fact, the behavior of

the /WX switch is dependent on the warning level set (/W0 - /W4), and

only suppresses creation of the .OBJ for warnings that occur at the

currently set warning level.

More Information:

The online Help for C versions 6.0, 6.0a, 6.0ax, and C/C++ 7.0 states

the following for the /WX switch (which the online Help also refers to

as warning level 5):

Causes warnings to be treated like errors. A warning inhibits

creation of an object file and causes the compiler to generate a

nonzero return code. The command line equivalent is /WX.

Page 103 of the "Microsoft QuickC Tool Kit" version 2.5 manual states

the following for the /WX switch:

Treats all warnings as fatal errors. If there are any warning

messages, the compilation aborts and QCL does not produce an object

file.

Both of these statements imply that the /WX switch causes warnings of

any type to result in compilation being aborted and no .OBJ to be

produced, but /WX works in conjunction with /W{0|1|2|3|4} and behaves

accordingly, only stopping warnings that would normally occur at that

level.

The sample code below has an error that will generate a level 3 (/W3)

warning. However, if compiled with the /WX switch alone, no warnings

will be generated because the default is /W1. Therefore, the object

file will be produced, which is expected behavior, because you want to

halt compilation only for warnings that are actually generated.

Otherwise, you could halt compilation, yet not get a warning.

If the /WX switch is specified in conjunction with /W3 or /W4, the

following warning and error are generated as expected:

warning C4035: 'main' : no return value

error C2220: warning treated as error - no object file generated

Sample Code

-----------

/* Compile options: /c /WX (No warnings -- .OBJ file is created.)

/c /WX /W3 (Warning and error -- no .OBJ created.)

*/

int main(void)

{

int x = 5;

}

Additional reference words: 6.00 6.00a 6.00ax 7.00

#:n65a

{ewl navigate.dll, ewcright, /f"INF: /WX Compiler Switch Behavior Determined by /W{0|1|2|3|4}"}