cpp

C preprocessor 

Command


SYNOPSIS

cpp [-C] [-D name[=value]]... [-dD] [-dM] [-E] [-I directory]... [-lang-c|-lang-c++|-lang-fortran] [-M [-MM [-MD file] [-MMD file] [-N] [-o outfile] [-r directory]... [-Stext] [-Uname] [-whitespae] infile


DESCRIPTION

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:

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 -o is specified.

Using the cpp utility is not the same as using cc with the -E or -P options.

Options

-C 

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.

-Dname[=value

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 -D options to define name more than once, the rightmost definition is the one used.

Note:

On non-UNIX systems, all alphabetic text is forced to uppercase.

-dM 

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.

-dD 

is similar to -dM but -dD omits 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 -E option is given.

-I directory  

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 -I are searched before the system header file directories, you can use this option to override system header files.

If you specify multiple -I options, the directories specified are searched in the order specified (from left to right) before any system header file directories are searched.

Note:

On non-UNIX systems, directory is forced to uppercase.

-lang-c 

specifies the source language as C. This option is ignored in the MKS Toolkit version.

-lang-c++ 

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.

-lang-fortran 

specifies the source language as FORTRAN. When specified, whitespace specified in the input is not removed when generating the output.

-M 

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.

-MD file 

is similar to the -M but the dependency information is written to file. Unlike the -M option, this option still performs normal compilation.

-MM 

is similar to -M but the created make rule only incudes those files specified with #include file.

System header files included with #include file are omitted.

-MMD file 

is similar to -MD but 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.

If -N is specified, the "always present" symbols, __LINE__, __FILE__, and __DATE__ are not defined.

-o outfile 

writes the processed output to outfile.

-Stext 

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.

-Uname  

undefines the name as if the program included:

#undef name

If both -U and -D are specified for the same name, the name is not defined.

Note:

On non-UNIX systems, name is forced to uppercase.

-whitespace 

does not remove whitespace specified in the input when generating the output.

Predefined Macros

Several object-like macros are predefined, you can use them without supplying their definitions.

Standard Predefined Macros

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.

__FILE__ 

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.

__LINE__ 

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.

__DATE__ 

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.

__TIME__ 

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.

__STDC__ 

normally expands to the constant 1, to signify that this compiler conforms to ISO Standard C.

System Specific Predefined Macros

These options are specific to the platforms and the Microsoft Visual C++ compilers supported by the MKS Toolkit.

_MSC_VER 

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
_WIN32 

is defined for Win32 applications and is always defined as 1.

_M_IX86 

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


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

>0 

An error occurred.


AVAILABILITY

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


SEE ALSO

Commands:
cc


PTC MKS Toolkit 10.5 Documentation Build 40.