cpp: Overview

1 
1 1 Overview
1 **********
1 
1 The C preprocessor, often known as "cpp", is a "macro processor" that is
1 used automatically by the C compiler to transform your program before
1 compilation.  It is called a macro processor because it allows you to
1 define "macros", which are brief abbreviations for longer constructs.
1 
1    The C preprocessor is intended to be used only with C, C++, and
1 Objective-C source code.  In the past, it has been abused as a general
1 text processor.  It will choke on input which does not obey C's lexical
1 rules.  For example, apostrophes will be interpreted as the beginning of
1 character constants, and cause errors.  Also, you cannot rely on it
1 preserving characteristics of the input which are not significant to
1 C-family languages.  If a Makefile is preprocessed, all the hard tabs
1 will be removed, and the Makefile will not work.
1 
1    Having said that, you can often get away with using cpp on things
1 which are not C.  Other Algol-ish programming languages are often safe
1 (Pascal, Ada, etc.)  So is assembly, with caution.  '-traditional-cpp'
1 mode preserves more white space, and is otherwise more permissive.  Many
1 of the problems can be avoided by writing C or C++ style comments
1 instead of native language comments, and keeping macros simple.
1 
1    Wherever possible, you should use a preprocessor geared to the
1 language you are writing in.  Modern versions of the GNU assembler have
1 macro facilities.  Most high level programming languages have their own
1 conditional compilation and inclusion mechanism.  If all else fails, try
1 a true general text processor, such as GNU M4.
1 
1    C preprocessors vary in some details.  This manual discusses the GNU
1 C preprocessor, which provides a small superset of the features of ISO
1 Standard C.  In its default mode, the GNU C preprocessor does not do a
1 few things required by the standard.  These are features which are
1 rarely, if ever, used, and may cause surprising changes to the meaning
1 of a program which does not expect them.  To get strict ISO Standard C,
1 you should use the '-std=c90', '-std=c99', '-std=c11' or '-std=c17'
1 options, depending on which version of the standard you want.  To get
11 all the mandatory diagnostics, you must also use '-pedantic'.  ⇒
 Invocation.
1 
1    This manual describes the behavior of the ISO preprocessor.  To
1 minimize gratuitous differences, where the ISO preprocessor's behavior
1 does not conflict with traditional semantics, the traditional
1 preprocessor should behave the same way.  The various differences that
1 do exist are detailed in the section ⇒Traditional Mode.
1 
1    For clarity, unless noted otherwise, references to 'CPP' in this
1 manual refer to GNU CPP.
1 

Menu