CPP(1) General Commands Manual CPP(1)NAME
cpp - C language preprocessor
SYNOPSIS
cpp [ option ... ] [ ifile [ ofile ] ]
DESCRIPTION
Cpp interprets ANSI C preprocessor directives and does macro substitution. The input ifile and output ofile default to standard input and
standard output respectively.
The options are:
-Dname
-Dname=def
-Idir Same as in 2c(1).
-M Generate no output except a list of include files in a form suitable for specifying dependencies to mk(1). Use twice to list files
in angle brackets.
-N Turn off default include directories. All must be specified with -I. Without this option, /$objtype/include and /sys/include are
used as the last two searched directories for include directives, where $objtype is read from the environment.
-V Print extra debugging information.
-+ Understand C++ comments.
The output file contains processed text sprinkled with lines that show the original input line numbering:
#line linenumber "ifile"
The input language is as described in the ANSI C standard. The C compilers do not use cpp; they contain their own simple but adequate pre-
processor, so cpp is usually superfluous.
FILES
/sys/include
directory for machine-independent include files
/$objtype/include
directory for machine-dependent include files
SOURCE
/sys/src/cmd/cpp
SEE ALSO 2c(1)CPP(1)
Check Out this Related Man Page
cpp(1) General Commands Manual cpp(1)Name
cpp - the C language preprocessor
Syntax
/lib/cpp [ option ... ] [ ifile [ ofile ] ]
Description
The command is the C language preprocessor which is invoked as the first pass of any C compilation using the command. Thus, the output of
is designed to be in a form acceptable as input to the next pass of the C compiler.
The preferred way to invoke however, is through the command. See for a general macro processor.
Arguments
The command optionally accepts two file names as arguments. The ifile and ofile are, respectively, the input and output for the preproces-
sor. They default to standard input and standard output if no argument is supplied.
Options-B Strips C++-style comments (begin with // and end with newline).
-C Passes along all comments, except those found on directive lines. By default, strips C-style comments.
-M Generates dependency lists suitable for use with instead of the normal output.
-P Preprocesses the input without producing the line control information used by the next pass of the C compiler.
-R Permits recursion when a macro is expanded.
-Uname Removes any initial definition of name, where name is a reserved symbol that is predefined by the preprocessor. The
symbols predefined by this implementation are bsd4_2, ultrix, unix, mips, host_mips, and MIPSEL.
-Dname
-Dname=def Defines name as if by a #define directive. If no =def is given, name is defined as 1. The -D option has lower prece-
dence than the -U option. That is, if the same name is used in both a -U option and a -D option, the name remains
undefined regardless of the order of the options.
-Idir Changes the algorithm for searching for #include files whose names do not begin with a slash ( / ) to look in dir
before looking in the directories on the standard list. Thus, #include files whose names are enclosed in quotes ( "" )
will be searched for first in the directory of the file with the #include line, then in directories named in -I
options, and, finally, in directories on a standard list. For #include files whose names are enclosed in angle brack-
ets (<>), the directory of the file with the #include line is not searched.
Directives
All directives start with lines that begin with a pound sign (#). Any number of blanks and tabs are allowed between the pound signs and
the directive. The following is a list of the directives:
#define name(arg, ...,arg ) token-string
Replaces subsequent instances of name and the following set of tokens that is enclosed in parentheses by token-string.
Each occurrence of an arg in the token-string is replaced by the corresponding set of tokens in the comma-separated
list. Note that spaces between name and the left parenthesis (() are not allowed. When a macro with arguments is
expanded, the arguments are placed unchanged into the expanded token-string . After the entire token-string has been
expanded, re-starts its scan for names to expand at the beginning of the newly created token-string.
#undef name Causes the definition of name (if any) to be forgotten.
#include "filename"
#include <filename> Includes the contents of filename , which will then be run through When the <filename> notation is used, filename is
searched for in the standard places. See the -I option above for more detail.
#line integer-constant "filename"
Causes to generate line control information for the next pass of the C compiler. Integer-constant is the line number
of the next line and filename is the file that it comes from. If "filename" is not given, the current file name is
unchanged.
#endif
Ends a section of lines begun by a test directive (#if, #ifdef, or #ifndef). Each test directive must have a matching
#endif.
#ifdef name Defines text that will appear in the output if name has been the subject of a previous #define without being the sub-
ject of an intervening #undef.
#ifndef name Defines text that will not appear in the output if name has been the subject of a previous #define without being the
subject of an intervening #undef.
#if constant-expression
Defines text that will appear in the output if constant-expression is not zero. All binary non-assignment C operators,
which include the ?: , en dash (-), exclamation mark (!), and tilde (~) are legal in constant-expression. The prece-
dence of the operators is the same as defined by the C language. There is also a unary operator defined, which can be
used in constant-expression in these two forms: defined ( name ) or defined name. This allows the utility of #ifdef
and #ifndef in a #if directive. Only these operators, integer constants, and names which are known by should be used
in constant-expression. In particular, the sizeof operator is not available.
#else Reverses the notion of the test directive which matches this directive. So if lines prior to this directive are
ignored, the following lines will appear in the output. The reverse is also true.
#elif constant-expression
Defines text that will appear in the output if the preceding test directive and all intervening #elif directives
equalled zero and the constant-expression did not equal zero. The rules for constant-expression are the same as for
the #if directive.
The test directives and the possible #else and #elif directives can be nested.
In addition to these directives, the System V #ident directive is recognized and ignored.
Two special names are understood by __LINE__ is defined as the current line number (as a decimal integer) and __FILE__ is defined as the
current file name (as a C string). They can be used in any situations where you would use other defined names, including in macros.
Diagnostics
The error messages produced by are self-explanatory. The line number and filename where the error occurred are printed along with the
diagnostic.
Files
/usr/include standard directory for #include files
See Alsocc(1), m4(1)
RISC cpp(1)