Only the most useful options are listed here; see below for the remainder.
DESCRIPTION
The C preprocessor is a macro processor that is used automatically
by the C compiler to transform your program before actual compilation.
It is called a macro processor because it allows you to define
macros, which are brief abbreviations for longer constructs.
The C preprocessor is intended only for macro processing of C, C++ and
Objective C source files. For macro processing of other files, you are
strongly encouraged to use alternatives like M4, which will likely give
you better results and avoid many problems. For example, normally the C
preprocessor does not preserve arbitrary whitespace verbatim, but
instead replaces each sequence with a single space.
For use on C-like source files, the C preprocessor 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, which are abbreviations
for arbitrary fragments of C code, and then the C preprocessor will
replace the macros 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.
C preprocessors vary in some details. This manual discusses the GNU C
preprocessor, which provides a small superset of the features of ISO
Standard C.
In its default mode, the GNU C preprocessor does not do a few things
required by the standard. These are features which are rarely, if ever,
used, and may cause surprising changes to the meaning of a program which
does not expect them. To get strict ISO Standard C, you should use the
-std=c89 or -std=c99 options, depending on which version
of the standard you want. To get all the mandatory diagnostics, you
must also use -pedantic.
OPTIONS
The C preprocessor expects two file names as arguments, infile and
outfile. The preprocessor reads infile together with any
other files it specifies with #include. All the output generated
by the combined input files is written in outfile.
Either infile or outfile may be -, which as
infile means to read from standard input and as outfile
means to write to standard output. Also, if either file is omitted, it
means the same as if - had been specified for that file.
Here is a table of command options accepted by the C preprocessor.
These options can also be given when compiling a C program; they are
passed along automatically to the preprocessor when it is invoked by the
compiler.
-P
Inhibit generation of #-lines with line-number information in the
output from the preprocessor. This might be useful when running the
preprocessor on something that is not C code and will be sent to a
program which might be confused by the #-lines.
-C
Do not discard comments. All comments are passed through to the output
file, except for comments in processed directives, which are deleted
along with the directive. Comments appearing in the expansion list of a
macro will be preserved, and appear in place wherever the macro is
invoked.
You should be prepared for side effects when using -C; it causes
the preprocessor to treat comments as tokens in their own right. For
example, macro redefinitions that were trivial when comments were
replaced by a single space might become significant when comments are
retained. Also, comments appearing at the start of what would be a
directive line have the effect of turning that line into an ordinary
source line, since the first token on the line is no longer a #.
-traditional
Try to imitate the behavior of old-fashioned C, as opposed to ISO C.
*
Traditional macro expansion pays no attention to single-quote or
double-quote characters; macro argument symbols are replaced by the
argument values even when they appear within apparent string or
character constants.
*
Traditionally, it is permissible for a macro expansion to end in the
middle of a string or character constant. The constant continues into
the text surrounding the macro call.
*
However, traditionally the end of the line terminates a string or
character constant, with no error.
*
In traditional C, a comment is equivalent to no text at all. (In ISO
C, a comment counts as whitespace.)
*
Traditional C does not have the concept of a ``preprocessing number''.
It considers 1.0e+4 to be three tokens: 1.0e, +,
and 4.
*
A macro is not suppressed within its own definition, in traditional C.
Thus, any macro that is used recursively inevitably causes an error.
*
The character # has no special meaning within a macro definition
in traditional C.
*
In traditional C, the text at the end of a macro expansion can run
together with the text after the macro call, to produce a single token.
(This is impossible in ISO C.)
*
None of the GNU extensions to the preprocessor are available in
-traditional mode.
Use the -traditional option when preprocessing Fortran code, so
that single-quotes and double-quotes within Fortran comment lines (which
are generally not recognized as such by the preprocessor) do not cause
diagnostics about unterminated character or string constants.
However, this option does not prevent diagnostics about unterminated
comments when a C-style comment appears to start, but not end, within
Fortran-style commentary.
So, the following Fortran comment lines are accepted with
-traditional:
C This isn't an unterminated character constant
C Neither is "20000000000, an octal constant
C in some dialects of Fortran
However, this type of comment line will likely produce a diagnostic, or
at least unexpected output from the preprocessor, due to the
unterminated comment:
C Some Fortran compilers accept /* as starting
C an inline comment.
Note that "g77" automatically supplies the -traditional
option when it invokes the preprocessor. However, a future version of
"g77" might use a different, more-Fortran-aware preprocessor in
place of "cpp".
-trigraphs
Process ISO standard trigraph sequences. These are three-character
sequences, all starting with ??, that are defined by ISO C to
stand for single characters. For example, ??/ stands for
\, so '??/n' is a character constant for a newline. By
default, GCC ignores trigraphs, but in standard-conforming modes it
converts them. See the -std option.
The nine trigraph sequences are
??(
-> [
??)
-> ]
??<
-> {
??>
-> }
??=
-> #
??/
-> \
??'
-> ^
??!
-> |
??-
-> ~
Trigraph support is not popular, so many compilers do not implement it
properly. Portable code should not rely on trigraphs being either
converted or ignored.
-pedantic
Issue warnings required by the ISO C standard in certain cases such
as when text other than a comment follows #else or #endif.
-pedantic-errors
Like -pedantic, except that errors are produced rather than
warnings.
-Wcomment
-Wcomments
(Both forms have the same effect).
Warn whenever a comment-start sequence /* appears in a /*
comment, or whenever a backslash-newline appears in a // comment.
-Wtrigraphs
Warn if any trigraphs are encountered. This option used to take effect
only if -trigraphs was also specified, but now works
independently. Warnings are not given for trigraphs within comments, as
we feel this is obnoxious.
-Wwhite-space
Warn about possible white space confusion, e.g. white space between a
backslash and a newline.
-Wall
Requests -Wcomment, -Wtrigraphs, and -Wwhite-space
(but not -Wtraditional or -Wundef).
-Wtraditional
Warn about certain constructs that behave differently in traditional and
ISO C.
-Wundef
Warn if an undefined identifier is evaluated in an #if directive.
-Idirectory
Add the directory directory to the head of the list of
directories to be searched for header files.
This can be used to override a system header file, substituting your
own version, since these directories are searched before the system
header file directories. If you use more than one -I option,
the directories are scanned in left-to-right order; the standard
system directories come after.
-I-
Any directories specified with -I options before the -I-
option are searched only for the case of #include "file";
they are not searched for #include <file>.
If additional directories are specified with -I options after
the -I-, these directories are searched for all #include
directives.
In addition, the -I- option inhibits the use of the current
directory as the first search directory for #include "file".
Therefore, the current directory is searched only if it is requested
explicitly with -I.. Specifying both -I- and -I.
allows you to control precisely which directories are searched before
the current one and which are searched after.
-nostdinc
Do not search the standard system directories for header files.
Only the directories you have specified with -I options
(and the current directory, if appropriate) are searched.
By using both -nostdinc and -I-, you can limit the include-file
search path to only those directories you specify explicitly.
-nostdinc++
Do not search for header files in the C++-specific standard directories,
but do still search the other standard directories. (This option is
used when building the C++ library.)
-remap
When searching for a header file in a directory, remap file names if a
file named header.gcc exists in that directory. This can be used
to work around limitations of file systems with file name restrictions.
The header.gcc file should contain a series of lines with two
tokens on each line: the first token is the name to map, and the second
token is the actual name to use.
-Dname
Predefine name as a macro, with definition 1.
-Dname=definition
Predefine name as a macro, with definition definition.
There are no restrictions on the contents of definition, but if
you are invoking the preprocessor from a shell or shell-like program you
may need to use the shell's quoting syntax to protect characters such as
spaces that have a meaning in the shell syntax. If you use more than
one -D for the same name, the rightmost definition takes
effect.
Any -D and -U options on the command line are processed in
order, and always before -imacrosfile, regardless of the
order in which they are written.
-Uname
Do not predefine name.
Any -D and -U options on the command line are processed in
order, and always before -imacrosfile, regardless of the
order in which they are written.
-undef
Do not predefine any nonstandard macros.
-gcc
Define the macros __GNUC__, __GNUC_MINOR__ and
__GNUC_PATCHLEVEL__. These are defined automatically when you use
gcc -E; you can turn them off in that case with -no-gcc.
-Apredicate=answer
Make an assertion with the predicate predicate and answer
answer. This form is preferred to the older form -Apredicate(answer), which is still supported, because
it does not use shell special characters.
-A -predicate=answer
Disable an assertion with the predicate predicate and answer
answer. Specifying no predicate, by -A- or -A -,
disables all predefined assertions and all assertions preceding it on
the command line; and also undefines all predefined macros and all
macros preceding it on the command line.
-dM
Instead of outputting the result of preprocessing, output a list of
#define directives for all the macros defined during the
execution of the preprocessor, including predefined macros. This gives
you a way of finding out what is predefined in your version of the
preprocessor; assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
will show the values of any predefined macros.
-dD
Like -dM except in two respects: it does not include the
predefined macros, and it outputs both the #define
directives and the result of preprocessing. Both kinds of output go to
the standard output file.
-dN
Like -dD, but emit only the macro names, not their expansions.
-dI
Output #include directives in addition to the result of
preprocessing.
-M
Instead of outputting the result of preprocessing, output a rule
suitable for "make" describing the dependencies of the main source
file. The preprocessor outputs one "make" rule containing the
object file name for that source file, a colon, and the names of all the
included files, including those coming from -include or
-imacros command line options. If there are many included files
then the rule is split into several lines using \-newline.
-MM
Like -M, but mention only the files included with #include
"file" or with -include or -imacros command line
options. System header files included with #include <file>
are omitted.
-MFfile
When used with -M or -MM, specifies a file to write the
dependencies to. This allows the preprocessor to write the preprocessed
file to stdout normally. If no -MF switch is given, CPP sends
the rules to stdout and suppresses normal preprocessed output.
-MG
When used with -M or -MM, -MG says to treat missing
header files as generated files and assume they live in the same
directory as the source file. It suppresses preprocessed output, as a
missing header file is ordinarily an error.
This feature is used in automatic updating of makefiles.
-MP
This option instructs CPP to add a phony target for each dependency
other than the main file, causing each to depend on nothing. These
dummy rules work around errors "make" gives if you remove header
files without updating the "Makefile" to match.
This is typical output:-
/tmp/test.o: /tmp/test.c /tmp/test.h
/tmp/test.h:
-MQtarget
-MTtarget
By default CPP uses the main file name, including any path, and appends
the object suffix, normally ``.o'', to it to obtain the name of the
target for dependency generation. With -MT you can specify a
target yourself, overriding the default one.
If you want multiple targets, you can specify them as a single argument
to -MT, or use multiple -MT options.
The targets you specify are output in the order they appear on the
command line. -MQ is identical to -MT, except that the
target name is quoted for Make, but with -MT it isn't. For
example, -MT '$(objpfx)foo.o' gives
$(objpfx)foo.o: /tmp/foo.c
but -MQ '$(objpfx)foo.o' gives
$$(objpfx)foo.o: /tmp/foo.c
The default target is automatically quoted, as if it were given with
-MQ.
-H
Print the name of each header file used, in addition to other normal
activities.
-imacrosfile
Process file as input, discarding the resulting output, before
processing the regular input file. Because the output generated from
file is discarded, the only effect of -imacrosfile
is to make the macros defined in file available for use in the
main input.
-includefile
Process file as input, and include all the resulting output,
before processing the regular input file.
-idirafterdir
Add the directory dir to the second include path. The directories
on the second include path are searched when a header file is not found
in any of the directories in the main include path (the one that
-I adds to).
-iprefixprefix
Specify prefix as the prefix for subsequent -iwithprefix
options. If the prefix represents a directory, you should include the
final /.
-iwithprefixdir
Add a directory to the second include path. The directory's name is
made by concatenating prefix and dir, where prefix was
specified previously with -iprefix.
-isystemdir
Add a directory to the beginning of the second include path, marking it
as a system directory, so that it gets the same special treatment as
is applied to the standard system directories.
-x c
-x c++
-x objective-c
-x assembler-with-cpp
Specify the source language: C, C++, Objective-C, or assembly. This has
nothing to do with standards conformance or extensions; it merely
selects which base syntax to expect. If you give none of these options,
cpp will deduce the language from the extension of the source file:
.c, .cc, .m, or .S. Some other common
extensions for C++ and assembly are also recognized. If cpp does not
recognize the extension, it will treat the file as C; this is the most
generic mode.
Note: Previous versions of cpp accepted a -lang option
which selected both the language and the standards conformance level.
This option has been removed, because it conflicts with the -l
option.
-std=standard
-ansi
Specify the standard to which the code should conform. Currently cpp
only knows about the standards for C; other language standards will be
added in the future.
standard
may be one of:
iso9899:1990
iso9899:1990
c89
c89
The ISO C standard from 1990. c89 is the customary shorthand for
this version of the standard.
The -ansi option is equivalent to -std=c89.
iso9899:199409
iso9899:199409
The 1990 C standard, as amended in 1994.
iso9899:1999
iso9899:1999
c99
c99
iso9899:199x
iso9899:199x
c9x
c9x
The revised ISO C standard, published in December 1999. Before
publication, this was known as C9X.
gnu89
gnu89
The 1990 C standard plus GNU extensions. This is the default.
gnu99
gnu99
gnu9x
gnu9x
The 1999 C standard plus GNU extensions.
-ftabstop=NUMBER
Set the distance between tab stops. This helps the preprocessor
report correct column numbers in warnings or errors, even if tabs appear
on the line. Values less than 1 or greater than 100 are ignored. The
default is 8.
-$
Forbid the use of $ in identifiers. The C standard allows
implementations to define extra characters that can appear in
identifiers. By default the GNU C preprocessor permits $, a
common extension.
SEE ALSO
gcc(1), as(1), ld(1), and the Info entries for cpp, gcc, and
binutils.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.