|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
/P (Preprocess to a File)
This option preprocesses C and C++ source files and writes the preprocessed output to a file. The file has the same base name as the source file and a .i extension. In the process, all preprocessor directives are carried out, macro expansions are performed, and comments are removed. To preserve comments in the preprocessed output, use the /C option along with /P.
/P adds #line directives to the output, at the beginning and end of each included file and around lines removed by preprocessor directives for conditional compilation. These directives renumber the lines of the preprocessed file. As a result, errors generated during later stages of processing refer to the line numbers of the original source file rather than lines in the preprocessed file. To suppress the generation of #line directives, use /EP as well as /P.
The /P option suppresses compilation. It does not produce an .obj file, even if you use /Fo. You must resubmit the preprocessed file for compilation. /P also suppresses the output files from the /FA, /Fa, and /Fm options.
To set this compiler option in the Visual Studio development environment
- Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
- Click the C/C++ folder.
- Click the Preprocessor property page.
- Modify the Generate Preprocessed File property.
To set this compiler option programmatically
The following command line preprocesses
ADD.C, preserves comments, adds #line directives, and writes the result to a file,
CL /P /C ADD.C