The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C
compiler to transform your program before compilation. It is called a macro processor because it
allows you to define macros, which are brief abbreviations for longer constructs.
The C preprocessor implements the macro language used to transform C, C++, and Objective-C pro-
grams before they are compiled. It can also be useful on its own.
The C preprocessor is intended to be used only with C, C++, and Objective-C source code. In the past,
it has been abused as a general text processor. It will choke on input that does not obey C's lexical
rules. For example, apostrophes will be interpreted as the beginning of character constants, and cause
errors. Also, you cannot rely on it preserving characteristics of the input that are not significant to
C-family languages. If a Makefile is preprocessed, all the hard tabs will be removed, and the Makefile
will not work.
Having said that, you can often get away with using cpp on things that are not C. Other Algol-ish pro-
gramming languages are often safe (Pascal, Ada, etc.) So is assembly, with caution.
mode preserves more white space, and is otherwise more permissive. Many of the problems can be
avoided by writing C or C++ style comments instead of native language comments, and keeping
macros simple.
Wherever possible, you should use a preprocessor geared to the language you are writing in. Modern
versions of the GNU assembler have macro facilities. Most high level programming languages have
their own conditional compilation and inclusion mechanism. If all else fails, try a true general text
processor, such as GNU M4.
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 that are rarely, if ever, used, and may
cause surprising changes to the meaning of a program that does not expect them. To get strict ISO
Standard C, you should use the
standard you want. To get all the mandatory diagnostics, you must also use
Chapter 12 Invocation.
1.1. Initial processing
The preprocessor performs a series of textual transformations on its input. These happen before all
other processing. Conceptually, they happen in a rigid order, and the entire file is run through each
transformation before the next one begins. GNU CPP actually does them all at once, for performance
reasons. These transformations correspond roughly to the first three "phases of translation" described
in the C standard.
1. The input file is read into memory and broken into lines.
GNU CPP expects its input to be a text file, that is, an unstructured stream of ASCII characters,
with some characters indicating the end of a line of text. Extended ASCII character sets, such as
ISO Latin-1 or Unicode encoded in UTF-8, are also acceptable. Character sets that are not strict
supersets of seven-bit ASCII will not work. We plan to add complete support for international
character sets in a future release.
Different systems use different conventions to indicate the end of a line. GCC accepts the ASCII
control sequences LF, CR LF, CR, and LF CR as end-of-line markers. The first three are the
canonical sequences used by Unix, DOS and VMS, and the classic Mac OS (before OSX)
respectively. You may therefore safely copy source code written on any of those systems to a
or
-std=c89
-std=c99
options, depending on which version of the
Chapter 1.
Overview
-traditional
. Refer to
-pedantic
Need help?
Do you have a question about the ENTERPRISE LINUX 3 - USING CPP and is the answer not in the manual?
Questions and answers