Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cpp(1) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cc

m4

ld



CPP(1,C)                    AIX Commands Reference                     CPP(1,C)



-------------------------------------------------------------------------------
cpp



PURPOSE

Performs file inclusion and macro substitution on a C language source file.

SYNTAX

            +-----------+   +---------------+   +--------------+
/lib/cpp ---| +-------+ |---|  +--------+   |---+- -Dname   1 -+--->
            +-| -C    |-+   +--| -Uname |---+   +- -Dname=def -+
             ^| -P    ||      ^| -Xdeps | |
             || -Idir ||      || -ttarg | |
             || -H    ||      |+--------+ |
             || -M    ||      +-----------+
             |+-------+|
             +---------+
                                             +------------------------+
                                         >---|          +-----------+ |---|
                                             +- infile -|           |-+
                                                        +- outfile -+
-----------------
1 The default def is 1.

DESCRIPTION

The cpp program is the C-language preprocessor.  It reads infile and writes to
outfile (standard input and standard output, by default).  Although you can use
this preprocessor by itself, it is best to use it through the cc command, which
by default sends a C-language source file to the cpp command as the first pass
in compilation.

The cpp program recognizes two special names, __LINE__ (the current line
number) and __FILE__ (the current file name).  These names can be used anywhere
just as any other defined name.

All cpp directive lines must begin with a # (number sign).  These directives
are:

#define  name  token-string
                           Replaces subsequent instances of name with
                           token-string.

#define  name(arg,...,arg) token-string
                           Replaces subsequent instances of the sequence
                           name(arg ,...,arg) with token-string, where each
                           occurrence of arg in token-string is replaced with
                           the corresponding token in the comma-separated list.




Processed November 8, 1990         CPP(1,C)                                   1





CPP(1,C)                    AIX Commands Reference                     CPP(1,C)



                           Note that there must not be any space between name
                           and the left parenthesis.

#undef  name               Ignores the definition of name from this point on.

#include  "file"

#include  <file>           Includes at this point the contents of file, which
                           the cpp command then processes.

                           If you enclose file in double quotation marks
                           ("" ""), the cpp command first searches first in the
                           directory of infile, then in directories named with
                           the -I flag, and finally in directories on a
                           standard list.

                           If you use the <file> notation, the cpp command
                           searches for file only in the standard places and in
                           any directory named with the -I flag.  It does not
                           search the directory in which infile resides.

#if  expr                  Places subsequent lines in the output only if expr
                           evaluates to nonzero.  All the binary non-assignment
                           C operators, the "?:" operator, and the unary "-",
                           "!", and ~ operators are legal in expr.  The
                           precedence of the operators is the same as that
                           defined in the C Language.  There is also a unary
                           operator, defined, which can be used in expr in
                           these two forms:

                              defined (name)
                              defined name

                           This operator allows the #ifdef and #ifndef
                           utilities in a #if directive.  Only these operators,
                           integer constants, and names which are known by the
                           cpp command should be used in expr.  See cc.cfg in
                           the AIX Technical Reference for information on
                           predefined C-processor symbols.  The sizeof operator
                           is not available.

#ifdef  name               Places the subsequent lines in the output only if
                           name has been defined by a previous #define and has
                           not been undefined by an intervening #undef.

#ifndef  name              Places the subsequent lines in the output only if
                           name has not been defined by a previous #define
                           directive or has been undefined by an intervening
                           #undef directive.






Processed November 8, 1990         CPP(1,C)                                   2





CPP(1,C)                    AIX Commands Reference                     CPP(1,C)



#else                      Places subsequent lines in the output only if the
                           expression in the preceding #if directive evaluates
                           to false (and hence the lines following the #if and
                           preceding the #else directives have been ignored).

#elif  expr                Places subsequent lines in the output only if the
                           expression in the preceding #if directive evaluates
                           to false, and the expr expression evaluates to
                           nonzero.

#endif                     Ends a section of lines begun by a test directive
                           (#if, #ifdef, or #ifndef).  Each test directive must
                           have a matching #endif directive.

#line  num ["file"]        Includes line control information for the next pass
                           of the C compiler.  The num is the line number of
                           the next line and file is the file from which it
                           comes.  If you omit "file", the current file name
                           remains unchanged.

#                          The null statement consists of a single # on a line
                           of its own and performs no action.

You can nest the test directives and the possible #else directives.

FLAGS

-C      Copies source file comments to the output file.  If you omit this flag,
        the cpp command removes all comments (except those found on cpp
        directive lines).

-Dname[=def]
        Defines name as in a #define directive.  The default def is 1.

-Idir   Looks first in dir, then looks in the directories on the standard list
        for #include files with names that do not begin with a / (slash).  See
        the previous discussion of the #include directive.

-M      Generates Makefile dependencies and sends the result to standard error.

-P      Preprocesses input without producing line control information for the
        next pass of the C compiler.

-Uname  Removes any initial definition of name, where name is a reserved symbol
        predefined by the preprocessor.

-Xdeps  Generates Makefile dependencies to file deps.  -X does not suppress the
        generation of the expanded output for the next pass of the C compiler
        as does -M.  Together -X and -M suppress expanded output and write the
        makefile dependencies to deps.





Processed November 8, 1990         CPP(1,C)                                   3





CPP(1,C)                    AIX Commands Reference                     CPP(1,C)



-ttarg  Changes the default target name in the makefile dependency file to
        targ.  See example 5.

EXAMPLES

  1. To display the text that the preprocessor sends to the C compiler:

      /lib/cpp  pgm.c

    This command preprocesses the file "pgm.c" and writes the resulting text to
    standard output.  You may want to see the preprocessor output when looking
    for errors in your macro definitions.

  2. To create a file containing more readable preprocessed text:

      /lib/cpp  -P  -C  pgm.c  pgm.i

    This command preprocesses the file "pgm.c" and stores the result in the
    file "pgm.i".  It omits line numbering information intended for the C
    compiler (-P) and includes program comments (-C).

  3. To predefine macro identifiers:

      /lib/cpp  -DBUFFERSIZE=512  -DDEBUG  pgm.c  pgm.i

    This command defines "BUFFERSIZE" with the value "512" and "DEBUG" with the
    value "1" before preprocessing.

  4. To use #include files located in nonstandard directories:

      /lib/cpp  -I/u/tom/include  pgm.c

    This command looks in the current directory for quoted #include files, then
    in the directory "/u/tom/include", and finally in the standard directories.
    It looks in the directory "/u/tom/include" for angle-bracketed #include
    files (< >) and then in the standard directories.

  5. To generate makefile dependencies in file "depsfile":

      /lib/cpp pgm.c -Xdepsfile

    file "depsfile" would contain dependencies in the form:

      pgm.o: /usr/include/stdio.h

    The -t option allows the user to change the target name (left side of the
    ":"), for example:

      /lbin/cpp pgm.c -Xdepsfile -tpgm

    would generate dependencies in the form:




Processed November 8, 1990         CPP(1,C)                                   4





CPP(1,C)                    AIX Commands Reference                     CPP(1,C)



      pgm: /usr/include/stdio.h

FILES

/usr/include   Standard directory for #include files.

RELATED INFORMATION

See the following commands:  "cc", "m4", and "ld".














































Processed November 8, 1990         CPP(1,C)                                   5



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026