The cpp utility is a macro preprocessor that is used automatically by the C compiler to transform your program before actual compilation. cpp provides four separate facilities that you can use as you see fit:
Inclusion of header files. These are files of declarations that can be substituted into your program.
Macro expansion. You can define macros that cpp then replaces with their definitions throughout the program.
Conditional compilation. Using special preprocessing directives, you can include or exclude parts of the program according to various conditions.
Line control. If you use a program to combine or rearrange source files into an intermediate file which is then compiled, you can use line control to inform the compiler of where each source line originally came from.
The cpp utility provides a superset of the features of ANSI Standard C.
In many cases, you do not need to invoke cpp directly; the C compilers does it automatically. However, cpp is sometimes useful on its own.
cpp expects a file name, infile, as
an argument. It reads infile together with any other files
specified with #include within infile.
The processed output for these input files is written to the standard
output unless the
Using the cpp utility is not the same as using
cc with the
passes comments through to the output file. This allows the cpp output to be used as the input to a program such as lint that expects commands embedded in specially-formatted comments.
defines the name as if the program included:
#define name value
at the start of the first file. If =value is omitted, name is defined as having the value 1. If you use multiple
-Doptions to define name more than once, the rightmost definition is the one used.
On non-UNIX systems, all alphabetic text is forced to uppercase.
does not output the results of preprocessing, but instead outputs a list of #define directives for all the macros defined during the execution of cpp, including predefined macros. This gives you a way to find out what is predefined in your version of cpp. For example, assuming you have no file foo.h, the command:
touch foo.h; cpp -dM foo.h
outputs the values of any predefined macros.
is similar to -dM but
-dDomits the predefined macros and outputs both the #define directives and the result of preprocessing to the standard output. -E
always returns "success" to the operating system, even if errors were detected. Some fatal errors, such as a missing #include file, terminate cpp, returning "failure" even if the
-Eoption is given.
adds directory to the list of directories to be searched for header files (that is, the value of the %Include environment variable). Because directories specified with
-Iare searched before the system header file directories, you can use this option to override system header files.
If you specify multiple
-Ioptions, the directories specified are searched in the order specified (from left to right) before any system header file directories are searched.
On non-UNIX systems, directory is forced to uppercase.
specifies the source language as C. This option is ignored in the MKS Toolkit version.
specifies the source language as C++. When specified, it lets cpp handle C++ comment syntax and includes extra default include directories for C++. This option is ignored in the MKS Toolkit version.
specifies the source language as FORTRAN. When specified, whitespace specified in the input is not removed when generating the output.
outputs a rule suitable for make describing the dependencies of the main source file. cpp outputs one make rule containing the object file name for that source file, a colon, and the names of all included files. If there are many included files, the rule is split into several lines using \ to suppress the newlines.
is similar to the
-Mbut the dependency information is written to file. Unlike the -Moption, this option still performs normal compilation. -MM
is similar to
-Mbut the created make rule only incudes those files specified with #include file.
System header files included with #include file are omitted.
is similar to
-MDbut the created make rule includes only user header files not system header files. -N
does not predefine any symbols. Normally, cpp predefines some symbols defining the target computer and operating system.
-Nis specified, the "always present" symbols, __LINE__, __FILE__, and __DATE__ are not defined. -ooutfile
writes the processed output to outfile.
dynamically respecifies the sizes of the the target computer's basic variable types. Normally, cpp assumes that these sizes are the same as the sizes of these types on the host computer.
The text argument is a string of numbers, separated by commas, that specifies correct sizes. The sizes must be specified in the exact order:
char short int long float double
If you specify the option as
-S*text, pointers to these types are specified. -S* takes one additional argument for pointer to function (for example, int (*)()). For example, to specify sizes appropriate for a PDP-11, you would write:
c s i l f d func -S1,2,2,2,4,8, -S*2,2,2,2,2,2,2
Note that all values must be specified.
undefines the name as if the program included:
-Uand -Dare specified for the same name, the name is not defined.
On non-UNIX systems, name is forced to uppercase.
does not remove whitespace specified in the input when generating the output.
Several object-like macros are predefined, you can use them without supplying their definitions.
The standard predefined macros are specified by the C and C++ language standards. They are available with all compilers that implement those standards. Older compilers may not provide all of them. Their names all start with double underscores.
expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in #include or as the input file name argument. For example, /usr/local/include/myheader.h is a possible expansion of this macro.
expands to the current input line number, in the form of a decimal integer constant. While we call it a predefined macro, it's a pretty strange macro, since its "definition" changes with each new line of source code.
__FILE__ and __LINE__ are useful in generating an error message to report an inconsistency detected by the program; the message can state the source line at which the inconsistency was detected. For example:
fprintf (stderr, "Internal error: " "negative string length " "%d at %s, line %d.", length, __FILE__, __LINE__);
An #include directive changes the expansions of __FILE__ and __LINE__ to correspond to the included file. At the end of that file, when processing resumes on the input file that contained the #include directive, the expansions of __FILE__ and __LINE__ revert to the values they had before the #include (but __LINE__ is then incremented by one as processing moves to the line after the #include).
A #line directive changes __LINE__, and may change __FILE__ as well.
expands to a string constant that describes the date on which the preprocessor is being run. The string constant contains eleven characters and looks like Feb 12 1996. If the day of the month is less than 10, it is padded with a space on the left.
expands to a string constant that describes the time at which the preprocessor is being run. The string constant contains eight characters and looks like 23:59:01.
normally expands to the constant 1, to signify that this compiler conforms to ISO Standard C.
These options are specific to the platforms and the Microsoft Visual C++ compilers supported by the MKS Toolkit.
defines the compiler version for the versions supported by the current version of MKS Toolkit. Possible values include:
Microsoft Visual C++ 7.1 _MSC_VER = 1310 Microsoft Visual C++ 7.0 _MSC_VER = 1300 Microsoft Visual C++ 6.0 _MSC_VER = 1200 Microsoft Visual C++ 5.0 _MSC_VER = 1100
is defined for Win32 applications and is always defined as 1.
defines the processor. Possible values include:
Blend _M_IX86 = 500 Pentium _M_IX86 = 500 Pentium Pro _M_IX86 = 600 80386 _M_IX86 = 300 80486 _M_IX86 = 400
Possible exit status values are:
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.3 Documentation Build 39.