Most often when you use the C preprocessor you will not have to invoke it explicitly: the C compiler will do so automatically. However, the preprocessor is sometimes useful on its own.
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 outfile or both file names are omitted,
the standard output and standard input are used for the omitted file names.
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
'
#
'-lines with line-number information in
the output from the preprocessor (see Output). 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
'
-traditional
'
1.0e+4
' to be three tokens: `1.0e
', `+
',
and `4
'.
#
' has no special meaning within a macro definition
in traditional C.
\
' inside a macro argument suppresses the syntactic
significance of the following character.
Use the `-traditional
' option when preprocessing Fortran code,
so that singlequotes and doublequotes
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
'
??
', that are defined by ANSI C to
stand for single characters. For example, `??/
' stands for
`\
', so `'??/n'
' is a character constant for a newline.
Strictly speaking, the GNU C preprocessor does not support all
programs in ANSI Standard C unless `-trigraphs
' is used, but if
you ever notice the difference it will be with relief.
You don't want to know any more about trigraphs.
-pedantic
'
#else
' or `#endif
'.
-pedantic-errors
'
-pedantic
', except that errors are produced rather than
warnings.
-Wtrigraphs
'
-trigraphs
' or `-ansi
'; in the
future this restriction will be removed.
-Wcomment
'
/*
' appears in a `/*
'
comment, or whenever a Backslash-Newline appears in a `//
' comment.
-Wall
'
-Wtrigraphs
' and `-Wcomment
' (but not
`-Wtraditional
' or `-Wundef
').
-Wtraditional
'
-Wundef
'
#if
' directive.
-I directory
'
-I
' option,
the directories are scanned in left-to-right order; the standard
system directories come after.
-I-
'
-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
'
-I
' options
(and the current directory, if appropriate) are searched.
-nostdinc++
'
-remap
'
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.
-D name
'
1
'.
-D name=definition
'
-D
' for the same name, the rightmost definition takes
effect.
-U name
'
-U
' and `-D
' are
specified for one name, the `-U
' beats the `-D
' and the name
is not predefined.
-undef
'
-gcc
'
gcc -E
'; you can turn them off
in that case with `-no-gcc
'.
-A predicate(answer)
'
You can use `-A-
' to disable all predefined assertions; it also
undefines all predefined macros and all macros that preceded it on the
command line.
-dM
'
#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
'
-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.
-dI
'
#include
' directives in addition to the result of preprocessing.
-M [-MG]
'
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. If there are many included files then the
rule is split into several lines using `\
'-newline.
`-MG
' says to treat missing header files as generated files and assume
they live in the same directory as the source file. It must be specified
in addition to `-M
'.
This feature is used in automatic updating of makefiles.
-MM [-MG]
'
-M
' but mention only the files included with `#include "file"
'. System header files included with `#include <file>
' are omitted.
-MD file
'
-M
' but the dependency information is written to file.
This is in addition to compiling the file as specified---`-MD
' does
not inhibit ordinary compilation the way `-M
' does.
When invoking gcc
, do not specify the file argument.
gcc
will create file names made by replacing ".c" with ".d" at
the end of the input file names.
In Mach, you can use the utility md
to merge multiple dependency
files into a single dependency file suitable for using with the `make
'
command.
-MMD file
'
-MD
' except mention only user header files, not system
header files.
-H
'
-imacros file
'
-imacros file
'
is to make the macros defined in file available for use in the
main input.
-include file
'
-idirafter dir
'
-I
' adds to).
-iprefix prefix
'
-iwithprefix
'
options.
-iwithprefix dir
'
-iprefix
'.
-isystem dir
'
-x c
'
-x c++
'
-x objective-c
'
-x assembler-with-cpp
'
.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
'
standard may be one of:
iso9899:1990
iso9899:199409
c89
c89
' is the customary
shorthand for this version of the standard.
The `-ansi
' option is equivalent to `-std=c89
'.
iso9899:199x
c9x
x
'.
gnu89
gnu9x
-Wp,-lint
'
lint
embedded in
comments, and emit them preceded by `#pragma lint
'. For example,
the comment `/* NOTREACHED */
' becomes `#pragma lint NOTREACHED
'.
Because of the clash with `-l
', you must use the awkward syntax
above. In a future release, this option will be replaced by
`-flint
' or `-Wlint
'; we are not sure which yet.
-$
'
$
' in identifiers. The C standard does not
permit this, but it is a common extension.
Packaging copyright © 1988-2000 OAR Corporation
Context copyright by each document's author. See Free Software Foundation for information.