

C preprocessor               Overview              C preprocessor




Preprocessing  encompasses all tasks  that logically  precede the
translation  of a program.   The preprocessor  processes headers,
expands  macros, and  conditionally includes  or  excludes source
code.

***** Directives *****

The C preprocessor recognizes the following directives:


         #iiff         Include code if a condition is true
         #eelliiff       Include code if directive is true
         #eellssee       Include code if preceding directives fail
         #eennddiiff      End of code to be included conditionally



    #iiffddeeff      Include code if a given macro is defined
    #iiffnnddeeff     Include code if a given macro is not defined



    #ddeeffiinnee     Define a macro
    #uunnddeeff      Undefine a macro
    #iinncclluuddee    Read another file and include it
    #lliinnee       Reset current line number


A preprocessing directive is always introduced by the `#' charac-
ter.  The  `#' must be  the first non-white space  character on a
line,  but it  may  be preceded  by  white space  and  it may  be
separated from the directive name  that follows it by one or more
white space characters.

***** Preprocessing Operators *****

The  Standard defines  two operators that  are recognized  by the
preprocessor:  the  ``stringize'' operator  #,  and the  ``token-
paste'' operator ##.

The operator  # indicates  that the  following argument is  to be
replaced by  a string literal; this  literal names the preproces-
sing token that replaces the argument.  For example, consider the
macro:


    #define display(x) show((long)(x), #x)


When the preprocessor reads the line






COHERENT Lexicon                                           Page 1




C preprocessor               Overview              C preprocessor



    display(abs(-5));


it replaces it with the following:


    show((long)(abs(-5)), "abs(-5)");


The ##  operator performs ``token pasting'' --  that is, it joins
two tokens together, to create a single token.  For example, con-
sider the macro:


    #define printvar(x) printf("%d\n", variable ## x)


When the preprocessor reads the line


    printvar(3);


it translates it into:


    printf("%d\n", variable3);


In  the past,  token pasting  had been  performed by  inserting a
comment between the tokens to be pasted.  This no longer works.

***** Predefined Macros *****

The  ANSI Standard  describes the following  macros that  must be
recognized by the preprocessor:


         _ _DDAATTEE_ _Date of translation
         _ _FFIILLEE_ _Source-file name
         _ _LLIINNEE_ _Current line within source file
         _ _SSTTDDCC_ _Conforming translator and level
         _ _TTIIMMEE_ _Time of translation


For more information on any one of these macros, see its entry.

***** Conditional Inclusion *****

The preprocessor will  conditionally include lines of code within
a program.   The directives  that include code  conditionally are
defined in such a way that you can construct a chain of inclusion
directives to include exactly the material you want.




COHERENT Lexicon                                           Page 2




C preprocessor               Overview              C preprocessor



***** Macro Definition and Replacement *****

The preprocessor performs  simple types of macro replacement.  To
define a macro, use the preprocessor directive #ddeeffiinnee _i_d_e_n_t_i_f_i_e_r
_v_a_l_u_e.    The  preprocessor  scans   the  translation   unit  for
preprocessor tokens that match identifier; when one is found, the
preprocessor substitutes value for it.

***** cpp *****

Under COHERENT, C preprocessing  is done by the program cpp.  The
cc command runs  cpp as the first step in  compiling a C program.
cpp can also be run by itself.

cpp reads  each input file;  it processes directives,  and writes
its product on ssttddoouutt.

If the  -E option is  not used, cpp  also writes into  its output
statements of  the form #lliinnee _n _f_i_l_e_n_a_m_e, so  that the parser cc0
can  connect its  error  messages and  debugger  output with  the
original line numbers in your source files.

See the Lexicon entry on cpp for more information.

***** See Also *****

C language, cc, cpp






























COHERENT Lexicon                                           Page 3


