CL /P

Syntax

This option has no arguments. It is /P only.

Relations

The /P option

It translates to a combination of other options for the front-end C and C++ compilers (C1 and C1XX). These others are:

where filename is formed by appending the extension “.i” to the file name of the source file.

Behaviour (CL)

The /P option leaves only the front-end C and C++ compilers as active. It disables all the remaining build stages: namely, Processing, Generating Code and Linking (though Processing can later be enabled by following with /B1_5).

Standard Output

CL understands the primary outcome from the compiler modules is to write text to standard output, albeit with the compiler modules expected to have redirected their standard output to filename. CL protects this outcome by disabling a mechanism that might otherwise cause the compiler modules to write other text to standard output.

Specifically, the /P option stops CL from duplicating standard output as standard error. Both CL (after its command-line analysis) and the compiler modules write most text, particularly error and warning messages and related notes, to standard error. By duplicating standard output as standard error before executing compiler modules, CL arranges that these messages, though still written to standard error, end up with whatever file or device CL was given as standard output. The ordinarily desirable effect is that these messages become subject to command-line redirection for easy capture to a file. Use of /P implies that this effect is not wanted. Whatever text the compiler modules are expected to produce because of /P goes to filename, but error messages, etc, go to the file or device that was given to CL as standard error (and are not subject to command-line redirection).

For example, check that no file named RUBBISH.H exists, then create TEST.CPP containing

#define TEST

#include    "rubbish.h"

The idea is that first line suffices for producing something non-trivial from the preprocessor (for output to a file named TEST.I) before the second line produces a fatal error (C1083). Now run the command

cl /P /rubbish test.cpp >test.txt

This produces a warning from CL for the unrecognised /rubbish option and a fatal error from C1XX for the attempted inclusion of the non-existent RUBBISH.H header. However, neither message is captured to TEST.TXT, which remains empty.

Behaviour (Compiler Modules)

As far as concerns the compiler module C1XX, the /P option is exactly a /E except that C1XX redirects its standard output to filename. It is a fatal error (C1083) if C1XX cannot open filename for read-write access in text mode.