CPP32.EXE, the C Compiler Preprocessor
Go Up to Command-Line Utilities Index
CPP32.EXE produces a 32-bit Windows file that lists a C or C++ program, in which all #include
files and #define
macros have been expanded. While you do not need to use the preprocessor during normal compilation, you may find the list file helpful for debugging purposes.
Often, when the compiler reports an error inside a macro or an include file, you can get more information about what the error is if you can see the include files or the results of the macro expansions. In many multipass compilers, a separate pass performs this work, and the results of the pass can be examined. Because the C++Builder compiler is a single-pass compiler, use CPP32 to get the first-pass functionality found.
For each file processed by CPP32, the output is written to a file in the current directory (or the output directory named by the -n
option) with the same name as the source name but with an extension of .I
.
This output file is a text file containing each line of the source file and any include files. Any preprocessing directive lines have been removed, along with any conditional text lines excluded from the compile. Within a text line, any macros are replaced with their expansion text.
By default, the generated text lines are prefixed with the comments containing the file name and line number of the source or include file the line came from. Use the -Sr
option to produce a file that does not have these comments. You can then pass this file to the compiler (use the -P
compiler option to force a C++ compile).
Contents
Command-Line Syntax
CPP32 [<options>] <filename[s]>
Command-Line Elements
Element | Description |
---|---|
|
Command-line options. They are optional. |
|
Defines a file to be processed. Several files can be specified. At least one file should be specified. |
To display the short command-line help, enter:
cpp32 -h
Or enter:
cpp32 -h -
to display all command-line help.
Command-Line Options
CPP32 recognizes all the same options that BCC32 does, and the following additional -Sx
options (controlling the preprocessing output format):
-Sx
Options
Option | Description |
---|---|
|
Keep comments in preprocessed file. |
|
Keep #define and #undef in preprocessed file. |
|
Keep output file on errors. |
|
Generate #line style output. |
|
Accept IDL-specific syntax. |
|
Make output readable by preserving comments and indentations. |
|
Show statistics of file names and line counts. |
CPP32 as a Macro Preprocessor
CPP32 can be used as a macro preprocessor. The resulting .i file can then be compiled with BCC32. The following simple program illustrates how CPP32 preprocesses a file.
Source file: HELLOCPP.C
#define NAME "C++Builder"
#define BEGIN {
#define END }
main()
BEGIN
printf("%s\n", NAME);
END
CPP32 Command Line
Execute:
CPP32 HELLOCPP.C
Output (written to HELLOCPP.I)
/* HELLOCPP.C 1: */
/* HELLOCPP.C 2: */
/* HELLOCPP.C 3: */
/* HELLOCPP.C 4: */
/* HELLOCPP.C 5: */main()
/* HELLOCPP.C 6: */{
/* HELLOCPP.C 7: */printf("%s\n", "C++Builder");
/* HELLOCPP.C 8: */}
/* HELLOCPP.C 9: */
Using MIDL with CPP32
MIDL (Microsoft Interface Definition Language) is an RPC compiler. In order to use MIDL with the C++ preprocessor (CPP32.EXE), you must use the following MIDL command:
MIDL -cpp_cmd {CPP32} -cpp_opt "-Sr -oCON {CPP32 options}" {MIDL options} {.idl/.acf file}
Here we use the following options:
Option | Description |
---|---|
|
Indicates MIDL which preprocessor to use when processing an .IDL or .ACF file. MIDL calls the preprocessor to expand macros within source files. |
|
Specifies the command-line options for the preprocessor. The |
|
Passes the options to CPP32. |
|
Any MIDL command-line options. |
|
The source file that MIDL processes. |
BCC32, CPP32 and UUIDs
In some cases, CPP32 does not accept valid UUIDs. For example, a valid UUID statement is:
uuid(5630EAA0-CA48-1067-B320-00DD010662DB)
When CPP32 encounters 5630EAA0
, it is classified as a floating-point number, and since it is an invalid floating-point number, the preprocessor emits an error. To work around this problem, enclose UUID within quotation marks. When using MIDL with CPP32, use the -ms_ext
option. The UUID statement becomes:
uuid("5630EAA0-CA48-1067-B320-00DD010662DB")
and the MIDL command line becomes:
MIDL -ms_ext CPP32 -cpp_opt "-Sr {CPP32 options}" {MIDL options} {.idl/.acf file}