The C Preprocessor is a separate step in the compilation process, but not part of the compiler.
A D V E R T I S E M E N T
C Preprocessor is just a text substitution tool and we'll refer to the C Preprocessor as the CPP.
The C Preprocessor
All preprocessor lines always begin
with #. This listing is from Weiss pg. 104.
The unconditional directives
are as follows:
#define -
Define a preprocessor macro
#include -
Insert a particular header
from another file
#undef -
Undefine a preprocessor
macro
The conditional directives are as follows:
#ifndef -
If this macro is not defined
#ifdef - If
this macro is defined
#if - Test
if a compile time condition
is true
#elif -
#else and #if in one
statement
#else - The
alternative for #if
#endif -
End preprocessor conditional
Other directives include:
## - Token
merge, creates a single
token from two adjacent ones
# -
Stringization, replaces a
macro parameter with a
string constant
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.
#define MAX_ARRAY_LENGTH 20
The above code will tell the CPP to replace instances of MAX_ARRAY_LENGTH with 20.
To increase readability,use #define for constants.
#include <stdio.h>
#include "mystring.h"
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.
#undef MEANING_OF_LIFE
#define MEANING_OF_LIFE 42
The above code tells the CPP to undefine MEANING_OF_LIFE and define it for 42.
#ifndef IROCK
#define IROCK "You wish!"
#endif
The above code tells the CPP to define IROCK only if IROCK isn't defined already.
#ifdef DEBUG
/* Your debugging statements here */
#endif
Thed above code tells the CPP to do the following statements if DEBUG is defined.If you pass the -DDEBUG flag to gcc,this is useful .
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
The C Preprocessor,
visual studio preprocessor,
c define,
define preprocessor,
if preprocessor,
preprocessor ifdef,
gnu preprocessor,
printf c,
c pointers,
sprintf c,
c tutorial,
c arrays,
fortran preprocessor,
preprocessor string,
c syntax,
c array,
c string,
void c,
preprocessor definition,
the c library